I just read this interesting article by Eric Lippert, Top 10 Worst C# Features. Near the end he states:
The rules for resolving names after the aforementioned colon are not well founded; you can end up in situations where you need to know what the base class is in order to determine what the base class is.
By colon he is referring to the inheritance operator (e.g. Dog : Animal
).
What situation is Eric referring to? Can anyone provide a code sample?
This can happen in convoluted scenarios with generics, inheritance, and nested classes:
class Base<T> { public class Inner {} } class Derived : Base<Derived.Inner2> { public class Inner2 : Inner {} }
Result
Derived
's base class, we need to bind Derived.Inner2
.Derived.Inner2
, we need to resolve the Inner
symbol.Inner
symbol is inherited from its containing scope's base class, so we need to determine Derived
's base class again.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With