Saturday 16 April 2016

Design a sorted list for all the course & perform following operations:

Fetch the values of list in sorted way
Find key of course B.Tech
Find out whether the list contains MCA or not & if not add this course to list
Get list of all the keys from sorted list
Remove course B.sc from the list

using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            SortedList sl = new SortedList();
            sl.Add("1", "BCA");
            sl.Add("2", "BJMC");
            sl.Add("3", "B.tech");
            sl.Add("4", "MBA");
            sl.Add("5", "B.sc");
            ICollection key = sl.Keys;
            foreach (string k in key)
            {
                Console.WriteLine(k + ": " + sl[k]);
            }



           


Console.WriteLine();
           Console.WriteLine();
           int i = 3;
          Console.WriteLine("The key  of B.tech  is {1}.",i , sl.GetKey(i));

           

Console.WriteLine();
            Console.WriteLine("Check MCA is There or Not ");
            if (sl.ContainsValue("MCA"))
            {
                Console.WriteLine("It is There ");
            }
            else
            {
                sl.Add("6", "MCA");
            }
            foreach (string k in key)
            {
                Console.WriteLine(k + ": " + sl[k]);
            }

           



 sl.Remove("5");
            Console.WriteLine();
            Console.WriteLine("Table After Removing B.Sc");
            foreach (string k in key)
            {
                Console.WriteLine(k + ": " + sl[k]);
            }

           Console.ReadKey();
        }
    }
}

No comments:

Post a Comment