Prev | Current Page 209 | Next

Jon Skeet

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

The feature has been carefully designed to cope
with most of the tasks that C++ programmers typically used templates for, but without
some of the accompanying disadvantages. However, this is not to say limitations don??™t
exist. There are some problems that C++ templates solve with ease but that C# generics
can??™t help with. Similarly, while generics in Java are generally less powerful than in
C#, there are some concepts that can be expressed in Java but that don??™t have a C#
equivalent. This section will take you through some of the most commonly encountered
weaknesses, as well as briefly compare the C#/.NET implementation of generics
with C++ templates and Java generics.
It??™s important to stress that pointing out these snags does not imply that they
should have been avoided in the first place. In particular, I??™m in no way saying that I
could have done a better job! The language and platform designers have had to balance
power with complexity (and the small matter of achieving both design and
implementation within a reasonable timescale). It??™s possible that future improvements
will either remove some of these issues or lessen their impact. Most likely, you
won??™t encounter problems, and if you do, you??™ll be able to work around them with the
guidance given here.
We??™ll start with the answer to a question that almost everyone raises sooner or later:
why can??™t I convert a List to List?
103 Limitations of generics in C# and other languages
3.


Pages:
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221