C#二维数组的初始化(IList>的初始化)

当输出为二维数组的时候,通常LeetCode需要的输出类型为IList>,这个时候,可能会遇到以下错误:

  IList> ans = new IList>();  // 无法创建抽象类或接口"IList>"的实例
  IList> ans = new List>(); 
//无法将类型"System.Collections.Generic.List < System.Collctions.Generic.List  >"隐式转换为
//"System.Collctions.Generic.lList>".存在一个显式转换(是否缺少强制转换?)

以上两种写法都会导致编译器报错。
正确的写法应该是

IList> ans = new List>();  // 通过

你可能感兴趣的:(C#二维数组的初始化(IList>的初始化))