在Visual Basic中,如果您要更改单个对象的多个属性,则可以使用
我知道在创建新对象时,C#可以做到这一点:
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, ...};
如果myObject
已经被创建了(就像Visual Basic所做的那样),那么我该如何做到这一点呢?
With
关键字。- http://msdn.microsoft.com/en-us/library/h63fsef3.aspx - Dan Atkinson