在Visual Basic中,如果要更改单个对象的多个属性,则需要With/End With声明:
Dim myObject as Object
// ' Rather than writing:
myObject.property1 = something
myObject.property2 = something2
// ' You can write:
with myObject
.property1 = something
.property2 = something2
...
End With
Run Code Online (Sandbox Code Playgroud)
我知道C#可以在创建新对象时执行此操作:
Object myObject = new Object { property1 = something, property2 = something2, ...};
Run Code Online (Sandbox Code Playgroud)
但是,如果myOject已经创建(如Visual Basic正在做什么),我该怎么做?