How to use C# List Class

Total Post:341

Points:2389
C# 
 1033  View(s)
Ratings:
Rate this:
I want to use list class in  c#.please help me
  1. Post:281

    Points:2003
    Re: How to use C# List Class

    The Collection classes are a group of classes designed specifically for grouping together objects and performing tasks on them. List class is a collection and defined in the System.Collections.Generic namespace and it provides the methods and properties like other Collection classes such as add, insert, remove, search etc.

    The C# List < T > class represents a strongly typed list of objects that can be accessed by index and it supports storing values of a specific type without casting to or from object. 

    List < T > 

    The parameter T is the type of elements in the list.

     

     

    
    

    using System;

    using System.Collections.Generic;

    using System.Diagnostics;

    using System.Linq;

    using System.Net;

    using System.Text;

    using System.Threading;

    namespace Forum

    {

        public class ChildClass

        {

            static void Main(string[] args)

            {

    // You can add items int List collection.

                List<Customer> CustomerList = new List<Customer>();

                Customer obj = new Customer();

                obj.CustomerID = 1;

                obj.CustomerName = "Visal";

                obj.ContactNumber = "8787878787";

                CustomerList.Add(obj);

                obj = new Customer();

                obj.CustomerID = 1;

                obj.CustomerName = "Visal";

                obj.ContactNumber = "9797979797";

                CustomerList.Add(obj);

                obj = new Customer();

                obj.CustomerID = 1;

                obj.CustomerName = "Visal";

                obj.ContactNumber = "77986521322";

                CustomerList.Add(obj);

    // You can retrieve items from List collection by using for loops.

                for (int i = 0; i < CustomerList.Count; i++)

                {

                    Console.WriteLine("CustomerID: {0}", CustomerList[i].CustomerID);

                    Console.WriteLine("CustomerName:{0}", CustomerList[i].CustomerName);

                    Console.WriteLine("ContactNumber:{0}", CustomerList[i].ContactNumber +"\n"); 

                }

    Console.ReadLine();

            }

        }

        public class Customer

        {

            public int CustomerID { get; set; }

            public String CustomerName { get; set; }

            public string  ContactNumber { get; set; }

        }

    }

    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqcAAAFXCAIAAAAQ/XDXAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAACKoSURBVHhe7d3rr61Xdd/x/ef4HX8CfUur1lREbclR1N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