TheBulgarianWolf

Arrays Basics

Jun 30th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;  
  3.  
  4. public class Program
  5. {
  6.     public static void Main()
  7.     {
  8.         /*int[] numbers = new int[5];
  9.         numbers[0] = 1;
  10.         numbers[1] = 5;
  11.         numbers[2] = 8;
  12.        
  13.         for(int i = 0;i<numbers.Length;i++)
  14.         {
  15.             Console.Write(numbers[i] + " ");   
  16.         }
  17.         */
  18.         //or
  19.         /*foreach(int number in numbers)
  20.         {
  21.             Console.Write(number + " ");
  22.         }
  23.         */
  24.        
  25.         //string[] names = new string[3]{"Thor", "Odin", "Loki"};
  26.         //List
  27.         /*List<int> numbers = new List<int>();
  28.         numbers.Add(5);
  29.         numbers.Add(15);
  30.         numbers.Add(25);
  31.         numbers.Add(35);
  32.         for(int i = 0;i<numbers.Count;i++)
  33.         {
  34.             Console.Write(numbers[i] + " ");
  35.         }
  36.         numbers.RemoveAt(2);
  37.         Console.WriteLine();
  38.         for(int i = 0;i<numbers.Count;i++)
  39.         {
  40.             Console.Write(numbers[i] + " ");
  41.         }
  42.         */
  43.         //Multidimentional array
  44.         CreateGrid();
  45.     }
  46.    
  47.     public static void CreateGrid()
  48.     {
  49.         int width = 6;
  50.         int height = 5;
  51.         int[,] grid = new int[width,height];
  52.         grid[2,3] = 5;
  53.         for(int x = 0;x<width;x++)
  54.         {
  55.             for(int y = 0;y<height;y++)
  56.             {
  57.                 Console.Write(grid[x,y] + " ");
  58.             }
  59.             Console.WriteLine();
  60.         }
  61.     }
  62. }
Add Comment
Please, Sign In to add comment