B
B
BitNeBolt2020-06-18 10:27:02
C++ / C#
BitNeBolt, 2020-06-18 10:27:02

Why does the studio itself implement the interface in this way?

There is an interface with one property. It must be implemented. When setting a colon, the Studio gives a hint that the interface is not implemented. If you use her help, then she will prescribe exceptions and nothing works.

Here is the working code,

using System;
class HelloWorld {
    public interface i 
    {
        int speed {get; set;}
    }

    class Object : i
    {
        public int speed {get; set;}
    }
    
  static void Main() {
      Object obj = new Object();
      obj.speed = 4;
      
    Console.WriteLine(obj.speed);
  }
}

which returns a value.

And created by the studio

using System;
class HelloWorld {
    public interface i 
    {
        int speed {get; set;}
    }

    class Object : i
    {
        public int speed {get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException();}
    }
    
  static void Main() {
      Object obj = new Object();
      obj.speed = 4;
      
    Console.WriteLine(obj.speed);
  }
}



At attempt to address the exception takes off.

Why does the studio do this, is it really necessary?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#, 2020-06-18
@BitNeBolt

- the F1 button works in the visual studio (I highly recommend it)
- the studio generated BLANKS for you ( they are quite meaningful so that you don’t forget to implement them )
- and this implies that you will enter the correct code there yourself. unlike the usual class property, the interface method cannot be empty .. and for this reason, it is filled with code that needs to be changed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question