C # language design - ducktyping

C # is basically a strong string, however there are several odd types of behavior:

eg. when you run your own enumerator class, you do not need to implement IEnumerable, you need to implement the GetEnuerator () method, you can still foreach over it.

The same applies to some Linq support, you can write your own Linq provider by simply providing some select where methods, etc.

So, what is IDisposable for using(x){} ?

I understand why the linq provider can be written this way, since there is no fixed contract for fullfill, only a kind of model of methods.

Why was the C # compiler (or language specification?) Designed in such a way that interfaces are needed for some built-in language constructs, but not for others?

+7
source share

All Articles