We continue with array. This time how we change the length of an array.

Arrays are immutable = cannot be changed in memory. However .Net Framework providers helper methods to resize an array… creates a new array and copies the old values into it.

Array.Resize(ref myArray, myArray.Length + 1);

//Get the highest index:

int highestIndex = myArray.GetUpperBound(0);

// 0 = dimension we want to retrieve the upper boundary for

//Arrays have other helper methods

myArray.Sum();

myArray.Min();

myArray.Max();

myArray.Average();

Array.Sort(myArray);

Array.Reverse(myArray);
Advertisements

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 )

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.