Saved Bookmarks
| 1. |
What is the difference between an Array and ArrayList in C#? |
|
Answer» An array is a collection of similar variables clubbed together under one common name. While ARRAYLIST is a collection of OBJECTS that can be indexed individually. With ArrayList you can access a number of features like dynamic MEMORY allocation, adding, searching, and sorting items in the ArrayList.
For ex.: // C# program to illustrate the ArrayListusing System;using System.Collections; class IB { // Main Method public static void Main(string[] args) { // Create a list of strings ArrayList al = new ArrayList(); al.Add("Bruno"); al.Add("Husky"); al.Add(10); al.Add(10.10); // Iterate list element using foreach loop foreach(var names in al) { Console.WriteLine(names); } }} |
|