Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我第一次遇到以下 C# 语法,我会把它当作语法错误丢弃,除非 VS 对它非常满意并且可以编译。
var a = new ISomeInterface[0];
接口声明为
public interface ISomeInterface { }
进一步阅读的链接也受到高度赞赏。
您已经创建了一个ISomeInterface.
ISomeInterface
这与声明任何其他数组相同,例如:
string[] a = new string[0];
起初我也对此进行了双重考虑,因为乍一看,代码似乎正在实例化一个接口,这是您通常无法做到的。
它正在创建一个新数组(零长度),而不是接口的新实例。顺便说一句,您实际上可以new在适当的条件下创建一个接口……;p(COM 属性)
new