What is difference between List and Dictionory in C# with 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);
            }
            Console.ReadLine();
        }
Share:

No comments:

Post a Comment

Monday, 21 May 2018

What is difference between List and Dictionory in C# with 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);
            }
            Console.ReadLine();
        }

No comments:

Post a Comment

Popular

Total Pageviews

Archive