Prev | Current Page 219 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"


Various smart people (including Eric Gunnerson and Anders Hejlsberg, who
ought to be able to think of C# tricks if anyone can) have thought about this, and with
a bit of extra code, some solutions have been found. They??™re slightly clumsy, but they
work. Unfortunately, due to current JIT optimization limitations, you have to pick
between pleasant syntax (x=y+z) that reads nicely but performs poorly, and a methodbased
syntax (x=y.Add(z)) that performs without significant overhead but looks like a
dog??™s dinner when you??™ve got anything even moderately complicated going on.
The details are beyond the scope of this book, but are very clearly presented at
http://www.lambda-computing.com/publications/articles/generics2/ in an article on
the matter.
The two limitations we??™ve looked at so far have been quite practical??”they??™ve been
issues you may well run into during actual development. However, if you??™re generally
curious like I am, you may also be asking yourself about other limitations that don??™t
necessarily slow down development but are intellectual curiosities. In particular, just
why are generics limited to types and methods?
14 More mathematically minded readers might want to consider what a Complex> would
mean. You??™re on your own there, I??™m afraid.
108 CHAPTER 3 Parameterized typing with generics
3.6.3 Lack of generic properties, indexers, and other member types
We??™ve seen generic types (classes, structs, delegates, and interfaces) and we??™ve seen
generic methods.


Pages:
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231