almost 6 years ago
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>(); list1.Add("CompanyName1"); list1.Add(101); Customer customarObj1 = new Customer(); list1.Add(customarObj1); list1.Add(112.350); list.Add(list1); // adding a list of object to our List List<object> list2 = new List<object>(); list1.Add("CompanyName2"); list1.Add(102); Customer customarObj2 = new Customer(); list1.Add(customarObj2); list1.Add(345.45); list.Add(list2); // adding a list of object to our List return 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>(); list1.Add("CompanyName1"); list1.Add(101); Customer customarObj1 = new Customer(); list1.Add(customarObj1); list1.Add(112.350); list.Add(list1); // adding a list of object to our List List<object> list2 = new List<object>(); list1.Add("CompanyName2"); list1.Add(102); Customer customarObj2 = new Customer(); list1.Add(customarObj2); list1.Add(345.45); list.Add(list2); // adding a list of object to our List return list; }
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)