2. C# - Arrays

 Declaring Arrays:

int[] myarray = new int[5];

// this declares a new empty array with 5 spots

// block brackets in front of a data type indicates its an array consisting of those data types


int[] myarray = int{1, 2, 3, 4};

// declares an array with preset values


Indexing Arrays:

Console.WriteLine(myarray[0]);

// prints "1"


Length Method:

myarray.Length // tells us length of array


Array Copy Method:

Array.Copy(sourceArray, destinationArray, numberofvaluestocopy);

// copies a set of values from one array and replaces those number of elements in the new array.


Array Sort Method:

Array.Sort(numberArray);

// sorts it into ascending order


Array IndexOf Method:

Array.IndexOf(arrayname, valuetofind);

// returns the index if it finds the value inside the array given

Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort