Chapter 6 explores arrays and collections in C#, covering fundamental concepts such as arrays, multidimensional arrays, jagged arrays, and key collection types like List, Dictionary, Queue, and Stack for efficient data handling.
int[] arr = new int(5);int arr = new int[5];int[] arr = {1, 2, 3, 4, 5};int[] arr = new int[] {1, 2, 3, 4, 5};Length()Count()array.Lengtharray.Count()arr in C#?arr[2]arr[3]arr[1]arr[0]int arr = {1, 2, 3, 4};int arr[4] = {1, 2, 3, 4};int[] arr = {1, 2, 3, 4};int[] arr = new int[] {1, 2, 3, 4};foreach(int item in arr) { Console.WriteLine(item); }for (int i = 0; i < arr.length; i++) { Console.WriteLine(arr[i]); }for each arr { Console.WriteLine(arr); }for (int item in arr) { Console.WriteLine(item); }int[2][2] arr;int[,] arr = new int[2, 2];int[2,2] arr = new int[2, 2];int[][] arr = new int[2, 2];arr at row 1, column 2?arr[1][2]arr[1, 2]arr(1, 2)arr[2, 1]int[,] arr = new int[3, 3]; arr[1, 1] = 5; Console.WriteLine(arr[1, 1]);int[,] matrix = new int[3][3];int[3, 3] matrix = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};int[,] matrix = {1, 2, 3, 4, 5, 6, 7, 8, 9};int[3, 3] matrix = new int[3, 3];int[2][] arr;int[][] arr = new int[2][];int[2][2] arr;int[] arr[2];int[][] jaggedArray = new int[2][]; jaggedArray[0] = new int[3]; jaggedArray[1] = new int[4]; Console.WriteLine(jaggedArray[0].Length);int[][] arr = new int[] { {1, 2}, {3, 4} };int[][] arr = new int[2] {1, 2, 3, 4};int[][] arr = new int[2][] { new int[] {1, 2}, new int[] {3, 4} };int arr[][] = { {1, 2}, {3, 4} };arr?Console.WriteLine(arr[0][0]);Console.WriteLine(arr[0]);Console.WriteLine(arr[1][0]);Console.WriteLine(arr[0]);List<T> in C#?List<int> in C#?list.Add(10);list.Insert(10);list[0] = 10;list.Append(10);Dictionary<TKey, TValue> in C#?Dictionary in C#?dictionary.GetValue(key);dictionary[key];dictionary.Get(key);dictionary.Lookup(key);Queue<T> in C#?Queue<T> in C#?queue.Enqueue(value);queue.Push(value);queue.Add(value);queue.Insert(value);Queue in C#?queue.Pop();queue.Dequeue();queue.Remove();queue.Delete();Stack<T> in C#?Stack<T> in C#?stack.Push(value);stack.Enqueue(value);stack.Add(value);stack.Insert(value);Stack in C#?stack.Dequeue();stack.Pop();stack.Remove();stack.Delete();List<T> in C#?| Qno | Answer |
|---|---|
| 1 | d) int[] arr = new int[] {1, 2, 3, 4, 5}; |
| 2 | a) 0 |
| 3 | c) array.Length |
| 4 | a) arr[2] |
| 5 | c) int[] arr = {1, 2, 3, 4}; |
| 6 | a) foreach(int item in arr) { Console.WriteLine(item); } |
| 7 | b) int[,] arr = new int[2, 2]; |
| 8 | b) arr[1, 2] |
| 9 | c) 5 |
| 10 | a) Yes |
| 11 | d) 32 |
| 12 | b) int[,] matrix = {1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 13 | a) An array of arrays |
| 14 | b) int[][] arr = new int[2][]; |
| 15 | a) Yes |
| 16 | b) 3 |
| 17 | c) int[][] arr = new int[2][] { new int[] {1, 2}, new int[] {3, 4} }; |
| 18 | a) Console.WriteLine(arr[0][0]); |
| 19 | b) Dynamic-size collection |
| 20 | a) list.Add(10); |
| 21 | b) It uses key-value pairs |
| 22 | b) dictionary[key]; |
| 23 | c) FIFO (First In, First Out) |
| 24 | a) queue.Enqueue(value); |
| 25 | b) queue.Dequeue(); |
| 26 | b) LIFO (Last In, First Out) |
| 27 | a) stack.Push(value); |
| 28 | b) stack.Pop(); |
| 29 | a) It supports dynamic resizing |
| 30 | b) Queue |