What is the differences among ArrayList, HashTable, List and Dictionoiry in C#? Example.

class Program
    {
        static void Main(string[] args)
        {
            List<int> li = new List<int>();
            li.Add(1);
            li.Add(2);
            li.Add(3);
            foreach (int i in li)
            {
                Console.WriteLine(i);
            }
            Dictionary<int,string> di = new Dictionary<int,string>();
            di.Add(1,"kul");
            di.Add(2, "raj");
            di.Add(3, "neha");

            foreach(KeyValuePair<int,string> ob in di)
            {
                Console.WriteLine(ob.Key +" "+ob.Value);
            }
            HashSet<int> ht = new HashSet<int>();
            ht.Add(1);
            ht.Add(2);
            ht.Add(3);
            foreach (int i in ht)
            {
                Console.WriteLine(i);
            }

            ArrayList obj = new ArrayList();
            obj.Add(1);
            obj.Add("kul");
            obj.Add("noida");
            foreach (object i in obj)
            {
                Console.WriteLine(i);
            }
            Console.ReadLine();
        }
    }
Share:

No comments:

Post a Comment

Monday, 21 May 2018

What is the differences among ArrayList, HashTable, List and Dictionoiry in C#? Example.

class Program
    {
        static void Main(string[] args)
        {
            List<int> li = new List<int>();
            li.Add(1);
            li.Add(2);
            li.Add(3);
            foreach (int i in li)
            {
                Console.WriteLine(i);
            }
            Dictionary<int,string> di = new Dictionary<int,string>();
            di.Add(1,"kul");
            di.Add(2, "raj");
            di.Add(3, "neha");

            foreach(KeyValuePair<int,string> ob in di)
            {
                Console.WriteLine(ob.Key +" "+ob.Value);
            }
            HashSet<int> ht = new HashSet<int>();
            ht.Add(1);
            ht.Add(2);
            ht.Add(3);
            foreach (int i in ht)
            {
                Console.WriteLine(i);
            }

            ArrayList obj = new ArrayList();
            obj.Add(1);
            obj.Add("kul");
            obj.Add("noida");
            foreach (object i in obj)
            {
                Console.WriteLine(i);
            }
            Console.ReadLine();
        }
    }

No comments:

Post a Comment

Popular

Total Pageviews

Archive