Prev | Current Page 208 | Next

Jon Skeet

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

Lists storing all their data in a plain array
(as List does) need to move all the entries that will come after the new one, which
can be very expensive??”and if the array runs out of spare capacity, the whole lot must
be copied. Enumerating a linked list from start to end is also cheap??”but random
access (fetching the fifth element, then the thousandth, then the second) is slower
than using an array-backed list. Indeed, LinkedList doesn??™t even provide a random
access method or indexer. Despite its name, it doesn??™t implement IList.
Linked lists are usually more expensive in terms of memory than their array-backed
cousins due to the extra link node required for each value. However, they don??™t have
the ???wasted??? space of the spare array capacity of List.
The linked list implementation in .NET 2.0 is a relatively plain one??”it doesn??™t support
chaining two lists together to form a larger one, or splitting an existing one into
two, for example. However, it can still be useful if you want fast insertions at both the
start and end of the list (or in between if you keep a reference to the appropriate node),
and only need to read the values from start to end, or vice versa.
Our final main section of the chapter looks at some of the limitations of generics
in C# and considers similar features in other languages.
3.6 Limitations of generics in C# and other languages
There is no doubt that generics contribute a great deal to C# in terms of expressiveness,
type safety, and performance.


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