在 VB.NET 中,您可以像这样实例化并立即使用数组:
Dim b as Boolean = {"string1", "string2"}.Contains("string1")
然而,在 C# 中,您似乎必须这样做:
bool b = new string[] { "string1", "string2"}.Contains("string1");
C# 是否具有等效的速记语法,使用类型推断来确定数组的类型而无需显式声明?
最佳答案
Implicitly typed arrays不必包括它们的类型,只要它可以是inferred :
bool b = new [] { "string1", "string2" }.Contains("string1");
关于c# - c# 是否有 VB.NET 等效的速记数组声明,如 {"string1","string2"}?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13973438/