Dictionary in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UsingDictionary
{
    class Customer
    {
        public string Name { get; set; }
        public int Salary { get; set; }
        public string City { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Customer c1 = new Customer { Name = "Raci", Salary = 20000, City = "Mumbai"};
            Customer c2 = new Customer { Name = "Ruchi", Salary = 204000, City = "bHOPAL" };
            Dictionary<int, Customer> cust = new Dictionary<int, Customer>();
            cust.Add(1, c1);
            cust.Add(2, c2);

            //int i;
            foreach (var i in cust)
            {
                Console.WriteLine("Employee Code: " + i.Key);
                if (cust.ContainsKey(i.Key))
                {
                    var customercity = cust[i.Key].City;
                    var customername = cust[i.Key].Name;
                    var customersalary = cust[i.Key].Salary;
                    Console.WriteLine(" Name: " + customername + " City: "
                    + customercity + " Salary: " + customersalary);
        }
    }
}

Ebook Download
View all
Learn
View all