Occasionally I see questions about edge cases and other weirdness on Stack Overflow that are easily answered by the likes of Jon Skeet and Eric Lippert, demonstrating a deep knowledge of the language and its many intricacies, like this one:
You might think that in order to use a
foreachloop, the collection you are iterating over must implement
IEnumerable<T>. But as it turns out, that is not actually a requirement. What is required is that the type of the collection must have a public method called
GetEnumerator, and that must return some type that has a public property getter called
Currentand a public method
MoveNextthat returns a
bool. If the compiler can determine that all of those requirements are met then the code is generated to use those methods. Only if those requirements are not met do we check to see if the object implements
That's cool stuff to know. I can understand why Eric knows this; he's on the compiler team, so he has to know. But what about those who demonstrate such deep knowledge who are not insiders?
How do mere mortals (who are not on the C# compiler team) find out about stuff like this?
Specifically, are there methods these folks use to systematically root out such knowledge, explore it and internalize it (make it their own)?