Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Arrays
- {
- class Program
- {
- static void Main(string[] args)
- {
- //To make an array you first define the data type.
- //Than you make a set of square brackets indicating it's an array you are declaring.
- //Finally you name your array like you would a normal variable.
- int[] myArray;
- //Next we initialize our array like so. The number in the square brackets defines the size of the array.
- myArray = new int[3];
- //We can assign values to the array by using an index like so:
- //Note: Arrays are zero based(the first position starts at 0).
- myArray[0] = 1;
- myArray[1] = 10;
- myArray[2] = 100;
- //And we can retrieve a value from an array using an index like so:
- Console.WriteLine(myArray[1]);
- //Arrays can be of any data type, for example, a string array.
- //They can have two, three or even more "dimensions".
- //We can declare and initialize an array in one line of code like so:
- string[,] mySecondArray = new string[5, 5];
- mySecondArray[0, 0] = "Hi.";
- Console.WriteLine(mySecondArray[0, 0]);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement