#122 – Arrays Can Contain Any Type of Object

C# arrays can be declared to contain any type of object, as long as all objects in the array are of the same type.

Here are some examples:

 // Arrays of fundamental types
 int[] numbers = new int[4];
 float[] morenums = { 1.1f, 2.2f };

 // Array of enum   (enum Moods { Cranky, Fearful, Wary };)
 Moods[] hourlyMoods = new Moods[24];

 // Array of object instances
 Person[] family = new Person[7];

Person bob = family[2];    // Reference one element
Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: