我的印象是C#编译器将隐式地键入一个基于一个类型的数组,它们都可以隐式转换为.
编译器为隐式类型数组生成 No best type
public interface ISomething {}
public interface ISomething2 {}
public interface ISomething3 {}
public class Foo : ISomething { }
public class Bar : ISomething, ISomething2 { }
public class Car : ISomething, ISomething3 { }
void Main()
{
var obj1 = new Foo();
var obj2 = new Bar();
var obj3 = new Car();
var objects= new [] { obj1, obj2, obj3 };
}
Run Code Online (Sandbox Code Playgroud)
我知道纠正这种情况的方法是声明类型:
new ISomething [] { obj1, ...}
Run Code Online (Sandbox Code Playgroud)
但是我在这里有一个封面类型的帮助.