views:

1656

answers:

7

Hi I know that c# has using element....but as you know, using disposes object automatically... clearly, I want the equivalence of with......end with in vb6.0?

Merci

+12  A: 

C# doesn't have an equivalent language construct for that.

Philippe Leybaert
this is true. But if you have a class with methods that return 'this', then you can chain the methods together.
Ziplin
+1  A: 

There's no equivalent to With ... End With in c#.

Here's a comparison chart for you that illustrates differences between vb and c#.

Joseph
A: 

There is no equivalent structure in C#. This is a VB6 / VB.Net feature.

JaredPar
A: 

I might be wrong but I don't think there is a "with ... end" equivalent in C#

tzup
Nope, there wasn't. But, then again, there was no IDisposable either :-)
Dan F
A: 

There is no such syntax construct. Similiar (like USING) exist, but there is no VB6- or Delphi-style WITH. This is done on purpouse, since nesting few with clauses makes code hard to understand.

smok1
+9  A: 

It's not equivalent, but would this syntax work for you?

Animal a = new Animal()
{
    SpeciesName = "Lion",
    IsHairy = true,
    NumberOfLegs = 4
};
tomfanning
+1  A: 

I think the equivalent of

With SomeObjectExpression()
  .SomeProperty = 5
  .SomeOtherProperty = "Hello"
End With

would be

{
  Var q=SomeOtherExpression();
  q.SomeProperty = 5;
  q.SomeOtherProperty = "Hello";
}

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.

supercat