Possible duplicate: "With ... End With" equivalence in C #?
So I donβt know if this question has been asked before, and I am not a big fan of VB.NET . But one syntax missing in C # is the syntax With.
With
In VB.NET you can write:
Dim sb As New StringBuilder With sb .Append("foo") .Append("bar") .Append("zap") End With
Is there any syntax in C # that I skipped that does the same?
No no.
This was deliberately excluded from C #, since it does not add much convenience, and because it can be easily used to write confusing code.
, Visual #, with: http://msdn.microsoft.com/en-us/vstudio/aa336816.aspx
StringBuilder :
StringBuilder
StringBuilder sb = new StringBuilder() .Append("foo") .Append("bar") .Append("zap");
VB With .
, StringBuilder.Append StringBuilder, :
StringBuilder.Append
sb.Append("foo").Append("bar").Append("zap");
sb.Append("foo") .Append("bar") .Append("zap");
/.
, .
With - VB/VB.NET.
New Type With:
New Type With
var obj = new Type { PropName = Value, PropName = Value };
With.
- Visual Basic.
, #, , , , With.