C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Why the <> in the names?

Chapter 6: Implementing iterators the easy way: 6.2.4

Created: 2/24/2008
Last updated: 2/24/2008

In the book, I mention that the types generated by iterator blocks always begin with <> and point out that this isn't indicating a generic type parameter. There's slightly more to it than that. Although the names are not indicating a generic type, it's no coincidence that they contain symbols used for generics. The name is deliberately constructed so it can't possibly be explicitly referenced by valid C# code.

The name also isn't CLS-compliant - which is fine, because the type itself is never public, and indeed never should be public. If ever a compiler accidentally made the types generated by iterator blocks public, any assembly claiming to be CLS-compliant would no longer compile, highlighting the compiler bug.