【问题标题】:C# to VB.NET syntax conversion for class instantiation with properties具有属性的类实例化的 C# 到 VB.NET 语法转换
【发布时间】:2010-10-14 18:15:53
【问题描述】:

我正在使用 Workflow Foundations 4(使用 C#)并尝试编写 VB.NET 表达式。有没有办法在 VB.NET 中单行执行以下操作?

SomeObj instance = new SomeObj()
{ 
    SomeStringProp = "a",
    SomeIntProp = 17
};

【问题讨论】:

  • 不幸的是,Window Workflow 4 没有(或当时没有)让您可以选择在活动的表达式中使用 C#。

标签: c# vb.net .net-4.0 anonymous-types


【解决方案1】:

这是一个例子:

Dim instance = new SomeObj() With {
    .ISomeStringProp = "a", 
    .SomeIntProp = 17
}

如果您想了解更多信息,请查看 VB.NET 9.0: Object and Array Initializers

【讨论】:

  • +1 在示例中,但认为关于谷歌的讽刺是不必要的。 Stackoverflow 应该包含困难和琐碎的答案,无论答案是否已经存在于互联网上的其他地方。
  • 出于好奇,您在谷歌搜索时使用的确切措辞是什么?
  • @terrance "object initializer vb.net" :)
猜你喜欢
  • 1970-01-01
  • 2013-01-10
  • 1970-01-01
  • 2023-03-09
  • 2022-06-15
  • 2023-03-15
  • 2016-06-16
  • 2016-06-20
  • 2011-12-15
相关资源
最近更新 更多