This question already has an answer here:
- With block equivalent in C#? 14 answers
I know that C# has the using
keyword, but using
disposes of the object automatically.
Is there the equivalence of With...End With
in Visual Basic 6.0?
This question already has an answer here:
I know that C# has the using
keyword, but using
disposes of the object automatically.
Is there the equivalence of With...End With
in Visual Basic 6.0?
C# doesn't have an equivalent language construct for that.
There is no equivalent structure in C#. This is a Visual Basic 6.0 / VB.NET feature.
There's no equivalent to With ... End With in C#.
Here's a comparison chart for you that illustrates differences between Visual Basic and C#.
It's not equivalent, but would this syntax work for you?
There is no equivalent, but I think discussing a syntax might be interesting!
I quite like;
Any other suggestions?
I cant imagine that adding this language feature would be difficult, essentially just a preprocessed.
EDIT:
I was sick of waiting for this feature, so here is and extension that achieves a similar behavior.
Usage;
EDIT: Interestingly it seems someone beat me to the punch, again, with this "solution". Oh well..
I think the equivalent of the following VB:
Would be this is C#:
The only real difference is that in vb, the identifier doesn't have a name "q", but is simply a default identifier used when a period is encountered without any other identifier before it.