Chapter 6
Lining Up Your Ducks with Collections
IN THIS CHAPTER
Creating variables that contain multiple items of data: Arrays
Going arrays one better with flexible “collections”
Looking at array and collection initializers and set-type collections
Simple one-value variables of the sort you may encounter in this book fall a bit short in dealing with lots of items of the same kind: ten ducks instead of just one, for example. C# fills the gap with two kinds of variables that store multiple items, generally called collections. The two species of collection are the array and the more general-purpose collection class.
An array is a data type that holds a list of objects of the same type. You can’t create a single array that contains both int
and double
objects, for example. Every object must be of the same type.
C# gives you quite ...
Get C# 7.0 All-in-One For Dummies 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.