Thursday, 24 May 2018

Collection Classes in C# Generic Classes







using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication29

{

    class Program

    {

        static void Main(string[] args)

        {

            string t;

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

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

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

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

            {

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

                t = Console.ReadLine();

                li.Add(t);

                Console.ForegroundColor = System.ConsoleColor.Green;

                Console.WriteLine("Data successfully added in list.....");

                Console.ReadLine();

                Console.Clear();

                Console.ForegroundColor = System.ConsoleColor.White;

           

            }

            Console.ForegroundColor = System.ConsoleColor.Green;

           

            Console.WriteLine("Press any key to print all names");

            Console.ReadLine();



            foreach (var item in li)

            {

                Console.ForegroundColor = System.ConsoleColor.Yellow;

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

            }



            Console.ReadLine();

        }

    }

}


No comments:

Post a Comment

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 ...