Tuesday 9 August 2016

Collection in C Sharp

/ Create a list of strings.
            var ob = new List<string>();
            ob.Add("Girfa");
            ob.Add("Student");
            ob.Add("Help");
            ob.Add("Blogger");

           
            // Iterate through the list.
            foreach (var t in ob)
            {
                Console.WriteLine(t + " ");
            }
            // More property and function abount collection
            Console.WriteLine("Capacity of Collection\t" + ob.Capacity);
            ob.Add("Website");
            //This will double the  capacity of current as showing in output
            Console.WriteLine("Capacity of Collection\t" + ob.Capacity);
            Console.WriteLine("Number of element in collection \t" + ob.Count);
            Console.WriteLine("element on 0 index \t" + ob.ElementAt(0));  

Next Topic

No comments:

Post a Comment