What is difference between IList and IList

前端 未结 3 1770
生来不讨喜
生来不讨喜 2021-01-13 03:32

Definition of List in .net shows it implement various interfaces.

public class List : IList, ICollection, I         


        
3条回答
  •  失恋的感觉
    2021-01-13 04:04

    In a IList you can only put the defined(T) type of object in and a IList can contain diffrent types of objects

    This code below will not complie because of the AdressInformation is not an valid object in customers List

    IList customers = new List();
    customers.Add(new Customer());
    customers.Add(new AdressInformation());
    

    This code will compile but cast an exception in runtime

    IList customers = new List();
    customers.Add(new Customer());
    customers.Add(new AdressInformation());
    

提交回复
热议问题