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# 中创建对象时,我们还可以(同时)填写其属性。这在 VB.NET 中可行吗?
例如:
MyObject obj = new MyObject { Name = "Bill", Age = 50 };
是的,有可能:
Dim obj As New MyObject With { .Name = "Bill", .Age = 50 }
两个重要的事情:
With
{ ... }
.Name
Name
对于集合初始值设定项,请使用From关键字:
From
Dim obj as New List(Of String) From { "String1", "String2" }