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()
- {
- //Declaration of Random
- Random ObjRandom = new Random();
- var v = ObjRandom.Next(0, 5);
- Console.WriteLine("Random Number is");
- Console.WriteLine(v);
- //Declaration of String Array
- string[] ObjArray = new string[5];
- ObjArray[0] = "Rajesh";
- ObjArray[1] = "Gonugunta";
- ObjArray[2] = "ABC";
- ObjArray[3] = "XYZ";
- ObjArray[4] = "DEF";
- //Declaration of Int Array
- int[] objInt = new int[5];
- objInt[0] = 100;
- objInt[1] = 200;
- objInt[2] = 300;
- objInt[3] = 400;
- objInt[4] = 500;
- //Creation of array list
- ArrayList ObjArraylist = new ArrayList();
- ObjArraylist.Add("Rajesh");
- ObjArraylist.Add(123);
- //Creation of Dictionary
- Dictionary < string, long > phonebook = new Dictionary < string, long > ();
- phonebook.Add("Rajesh", 415434543);
- phonebook["ABC"] = 415984588;
- //Creation of Hashtable
- Hashtable ht = new Hashtable();
- ht.Add("India", "1");
- ht.Add("Bangalore", "0");
- //Output of Int Array
- Console.WriteLine("Intiger array Output is");
- Console.WriteLine(objInt[v]);
- //Output of string Array
- Console.WriteLine("String array Output is");
- Console.WriteLine(ObjArray[v]);
- //Output of Int Array list
- Console.WriteLine("Arraylist Output is");
- Console.WriteLine(ObjArraylist[v]);
- //Output of Dictionary
- Console.WriteLine("Dictionary Output is");
- Console.ReadLine();
- }
- }
Intiger array Output is: 100
String array Output is: Rajesh
Arraylist Output is: Rajesh
Dictionary Output is: ABC number is 415984588

Alterius OmegaPosted Jul 25, 2022, 9:22 PM
Thanks, but why did you create the hash table if you never use it?
Guest UserPosted Jul 8, 2019, 7:48 AM
Nice code its working nice i love c-sharpcorner.com
kalu singh raoPosted Jul 1, 2016, 1:47 AM
Nice...