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

  1. using System.IO;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. //Declaration of Random
  12. Random ObjRandom = new Random();
  13. var v = ObjRandom.Next(0, 5);
  14. Console.WriteLine("Random Number is");
  15. Console.WriteLine(v);
  16. //Declaration of String Array
  17. string[] ObjArray = new string[5];
  18. ObjArray[0] = "Rajesh";
  19. ObjArray[1] = "Gonugunta";
  20. ObjArray[2] = "ABC";
  21. ObjArray[3] = "XYZ";
  22. ObjArray[4] = "DEF";
  23. //Declaration of Int Array
  24. int[] objInt = new int[5];
  25. objInt[0] = 100;
  26. objInt[1] = 200;
  27. objInt[2] = 300;
  28. objInt[3] = 400;
  29. objInt[4] = 500;
  30. //Creation of array list
  31. ArrayList ObjArraylist = new ArrayList();
  32. ObjArraylist.Add("Rajesh");
  33. ObjArraylist.Add(123);
  34. //Creation of Dictionary
  35. Dictionary < string, long > phonebook = new Dictionary < string, long > ();
  36. phonebook.Add("Rajesh", 415434543);
  37. phonebook["ABC"] = 415984588;
  38. //Creation of Hashtable
  39. Hashtable ht = new Hashtable();
  40. ht.Add("India", "1");
  41. ht.Add("Bangalore", "0");
  42. //Output of Int Array
  43. Console.WriteLine("Intiger array Output is");
  44. Console.WriteLine(objInt[v]);
  45. //Output of string Array
  46. Console.WriteLine("String array Output is");
  47. Console.WriteLine(ObjArray[v]);
  48. //Output of Int Array list
  49. Console.WriteLine("Arraylist Output is");
  50. Console.WriteLine(ObjArraylist[v]);
  51. //Output of Dictionary
  52. Console.WriteLine("Dictionary Output is");
  53. Console.ReadLine();
  54. }
  55. }
Output

Intiger array Output is: 100

String array Output is: Rajesh

Arraylist Output is: Rajesh

Dictionary Output is: ABC number is 415984588