List<T>

The generic counterpart of the ArrayList type is the generic List<T> type, where the type parameter T stands for, unsurprisingly, the element type. Available methods on List<T> are pretty much the same as on ArrayList. We can even easily port our ArrayList example to List<int>:

image

Named Parameters?

image You might have noticed before in the examples of nongeneric collection types that I’ve been using named parameters sometimes. This isn’t necessary to make the preceding code compile but serves as a form of documentation for the meaning of used ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.