Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Creating a Generic List in .Net

    • 0
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 79
    Comment on it

    Generic list are the list of object capable of storing any type, including Complex type such as class. It can even store a List of Items as well.

    Generic list is present in System.Collections.Generic Namespace in .Net frame work.

    As every type in .Net inherits directly or indirectly from System.Objects, so by creating a List of Object we can store any type in List.

    Example :

    Creating a Customer Class

    public class Customer
        public int ID { get; set; }
        public string CustomerName { get; set; }
        public int Address { get; set; }
        public int PhoneNo { get; set; }

    Now we create a list of Objects :

    public static List<List<object>> GetGerenicList()
                List<List<object>> list = new List<List<object>>(); // Creating a List of List of object
                List<object> list1 = new List<object>();
                Customer customarObj1 = new Customer();
                list.Add(list1); // adding a list of object to our List
                List<object> list2 = new List<object>();
                Customer customarObj2 = new Customer();
                list.Add(list2); // adding a list of object to our List
               return list;

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: