我有一个程序
using System;
using System.Collections.Generic;
namespace Generic
{
public class Program
{
public static void Main()
{
List<string> dd= Program.get();
}
public static IList<string> get()
{
List<string> str = new List<string>();
return str;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在执行上面我得到:
无法隐式转换
'System.Collections.Generic.IList<string>'为
'System.Collections.Generic.List<string>'.存在显式转换(您是否错过了演员?).
既然,List派生IList,这不应该失败.那么为什么C#会抛出这个错误呢?