#119 – Arrays

An array in C# is a type that contains a list of items of the same type.  Elements in the list can be referenced by a single variable name and a numerical index.  The first element is accessed using an index value of 0.

For example, below we define a four element array of integer (int) and set its elements to some hard-coded values.

 int[] numbers = new int[4];    //  Declare/create 4-element array of int

 // Set 4 elements to integer values
 numbers[0] = 10;    // 1st element
 numbers[1] = 20;
 numbers[2] = 30;
 numbers[3] = 40;

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

One Response to #119 – Arrays

  1. Pingback: #1,016 – Retrieving the Length of an Array | 2,000 Things You Should Know About C#

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: