Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Arrays
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //To make an array you first define the data type.
  10. //Than you make a set of square brackets indicating it's an array you are declaring.
  11. //Finally you name your array like you would a normal variable.
  12. int[] myArray;
  13.  
  14. //Next we initialize our array like so. The number in the square brackets defines the size of the array.
  15. myArray = new int[3];
  16.  
  17. //We can assign values to the array by using an index like so:
  18. //Note: Arrays are zero based(the first position starts at 0).
  19. myArray[0] = 1;
  20. myArray[1] = 10;
  21. myArray[2] = 100;
  22.  
  23. //And we can retrieve a value from an array using an index like so:
  24. Console.WriteLine(myArray[1]);
  25.  
  26.  
  27. //Arrays can be of any data type, for example, a string array.
  28. //They can have two, three or even more "dimensions".
  29. //We can declare and initialize an array in one line of code like so:
  30. string[,] mySecondArray = new string[5, 5];
  31. mySecondArray[0, 0] = "Hi.";
  32.  
  33. Console.WriteLine(mySecondArray[0, 0]);
  34.  
  35. Console.ReadLine();
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement