c# - c# 是否有 VB.NET 等效的速记数组声明,如 {"string1","string2"}?

标签 c# .net arrays types type-inference

在 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/

相关文章:

c# - 使用 C# Google.Protobuf 将 ByteString 反序列化为对象

c# - PatternString 类型何时在 Log4NET 中得到解析?

c# - 如何以 0,00 格式显示价格(即百 100,00)

.net - .Net 中的反射可以通过查看用户定义的类型名称来帮助动态构建表值参数/SqlMetaData [] 对象吗?

c# - Stripe Payment : System.Net.WebException:请求已中止:无法创建 SSL/TLS 安全通道

c# - Visual Studio 大型解决方案中最喜欢的项目

java - 如何找到数组中相邻的两个数字之间的最小距离?

c# - 如何四舍五入到某些数字

arrays - 获取最新日期

数组 0 键的 PHP json_encode 问题