在 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
我知道 C# 在创建新对象时可以做到这一点:
Object myObject = new Object { property1 = something, property2 = something2, ...};
但是,如果myOject
已经创建(就像 Visual Basic 正在做的那样),我该怎么做?