Is there a VB.NET "C" instruction in C #?

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.

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?

+5
source share
5 answers

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 sb = new StringBuilder()
  .Append("foo")
  .Append("bar")
  .Append("zap");
+11

VB With .

, StringBuilder.Append StringBuilder, :

sb.Append("foo").Append("bar").Append("zap");

sb.Append("foo")
  .Append("bar")
  .Append("zap");

/.

+4

, .

With - VB/VB.NET.

+2

New Type With:

var obj = new Type {
    PropName = Value,
    PropName = Value
};

With.

+2

- Visual Basic.

, #, , , , With.

0

All Articles