InterviewSolution
Saved Bookmarks
| 1. |
Array vs ArrayList in C# |
||||||||||||||||
|
Answer» Some of the major differences between an Array and an ARRAYLIST in C# are given as FOLLOWS:
A program that demonstrates an Array and ArrayList in C# is given as follows: using System; using System.Collections; namespace Demo { class Example { static void Main(string[] args) { int[] arr = new int[5]; arr[0] = 4; arr[1] = 7; arr[2] = 3; arr[3] = 9; arr[4] = 1; Console.Write("Array elements are: "); for (int i = 0; i < arr.Length; i++) { Console.Write(arr[i] + " "); } ArrayList arrList = new ArrayList(); arrList.Add(5); arrList.Add(1); arrList.Add(9); arrList.Add(7); arrList.Add(4); Console.Write("\nArrayList elements are: "); foreach (int i in arrList) { Console.Write(i + " "); } } } }The output of the above program is given as follows: Array elements are: 4 7 3 9 1 ArrayList elements are: 5 1 9 7 4 |
|||||||||||||||||