Array
An Array is collection of elements. Arrays are strongly typed collections of the same datatypes and these arrays ar a fixed length that cannot be changed during runtime.
Array List
Array lists are not strongly typed collections. They will store values of different datatypes or the same datatype. Array list size will increase or decrease dynamically; it can take any size of values from any data type.
Dictionary
A Dictionary class is a data structure that represents a collection of keys and value pairs of data. The key is identical in a key-value pair and it can have at most one value in the dictionary
Example Program
- using System.IO;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- class Program
- {
- static void Main()
- {
-
-
- Random ObjRandom = new Random();
- var v = ObjRandom.Next(0, 5);
-
- Console.WriteLine("Random Number is");
- Console.WriteLine(v);
-
-
- string[] ObjArray = new string[5];
- ObjArray[0] = "Rajesh";
- ObjArray[1] = "Gonugunta";
- ObjArray[2] = "ABC";
- ObjArray[3] = "XYZ";
- ObjArray[4] = "DEF";
-
-
- int[] objInt = new int[5];
- objInt[0] = 100;
- objInt[1] = 200;
- objInt[2] = 300;
- objInt[3] = 400;
- objInt[4] = 500;
-
-
-
-
- ArrayList ObjArraylist = new ArrayList();
- ObjArraylist.Add("Rajesh");
- ObjArraylist.Add(123);
-
-
-
- Dictionary < string, long > phonebook = new Dictionary < string, long > ();
- phonebook.Add("Rajesh", 415434543);
- phonebook["ABC"] = 415984588;
-
-
-
- Hashtable ht = new Hashtable();
- ht.Add("India", "1");
- ht.Add("Bangalore", "0");
-
-
-
- Console.WriteLine("Intiger array Output is");
- Console.WriteLine(objInt[v]);
-
-
- Console.WriteLine("String array Output is");
- Console.WriteLine(ObjArray[v]);
-
-
- Console.WriteLine("Arraylist Output is");
-
- Console.WriteLine(ObjArraylist[v]);
-
-
-
- Console.WriteLine("Dictionary Output is");
-
- Console.ReadLine();
- }
- }
Output
Intiger array Output is: 100
String array Output is: Rajesh
Arraylist Output is: Rajesh
Dictionary Output is: ABC number is 415984588