Thursday, 24 May 2018

List T in C# (GENERIC CLASSES)







class Employee

    {



        public int id { get; set; }

        public string name { get; set; }



    }





--------------------------------------------------------------------------



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication30

{

    class Program

    {

        static void Main(string[] args)

        {

            List<Employee> li = new List<Employee>();

            Console.WriteLine("How many records you want to add in list:");

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)

            {

                Console.ForegroundColor = System.ConsoleColor.Yellow;

                Console.WriteLine("Enter the name: ");

                Employee emp = new Employee();

                emp.name = Console.ReadLine();

                emp.id = i + 1;

                li.Add(emp);

                Console.ForegroundColor = System.ConsoleColor.Green;

                Console.WriteLine("1 RECORDS SUCCESSFULLY INSERTED IN LIST.......");

                Console.WriteLine("PRESS ANY KEY.....");

                Console.ReadLine();

                Console.Clear();



            }



            Console.WriteLine("PRESS ANY KEY.....");

            Console.ReadLine();

         

            foreach (var item in li)

            {

                Console.ForegroundColor = System.ConsoleColor.Red;

                Console.WriteLine("-----------------------------------------------");

                Console.ForegroundColor = System.ConsoleColor.Cyan;

                Console.WriteLine("ID: "+item.id);

                Console.WriteLine("Name: " + item.name);

                Console.ForegroundColor = System.ConsoleColor.Red;

                Console.WriteLine("-----------------------------------------------");

               



            }



            Console.ReadLine();

        }

    }

}


1 comment:

  1. Sir please Xml C# ki series b ak bna dain.. Jazak Allah

    ReplyDelete

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...