Hi,

Please could someone let me know if there is a equivalent command for C#

ie
vb.net

with object
.
.
.
end with

Re: VB.Net With Statement by Daniel

Daniel
Fri Apr 16 03:03:33 CDT 2004

No, there isn't.
"Rob Shorney" <fred.flintstone@bedrock.com> wrote in message
news:Oi4eZg4IEHA.3308@tk2msftngp13.phx.gbl...
> Hi,
>
> Please could someone let me know if there is a equivalent command for C#
>
> ie
> vb.net
>
> with object
> .
> .
> .
> end with
>
>



Re: VB.Net With Statement by Jon

Jon
Fri Apr 16 03:45:32 CDT 2004

Rob Shorney <fred.flintstone@bedrock.com> wrote:
> Please could someone let me know if there is a equivalent command for C#

No.

See http://www.pobox.com/~skeet/csharp/faq/#vb.with

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: VB.Net With Statement by Gabriele

Gabriele
Fri Apr 16 07:13:24 CDT 2004

As the other guys said, there's no direct equivalent of the VB.NET With
command.

You can get something close with the with the C# using keyword, but your
object must support the IDisposable interface
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfsystemidisposableclasstopic.asp).

Pen p = new Pen(Color.Black);
using(Pen o = p)
{
o.Color = Color.White;
}



Re: VB.Net With Statement by Jon

Jon
Fri Apr 16 07:49:22 CDT 2004

<"Gabriele G. Ponti" <ggponti.at.hotmail.com>> wrote:
> As the other guys said, there's no direct equivalent of the VB.NET With
> command.
>
> You can get something close with the with the C# using keyword, but your
> object must support the IDisposable interface
> (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
> /frlrfsystemidisposableclasstopic.asp).
>
> Pen p = new Pen(Color.Black);
> using(Pen o = p)
> {
> o.Color = Color.White;
> }

No, that's not similar at all - not only does it require the type to
implement IDisposable, but it calls Dispose at the end too.

Insetad, you can just do:

{
Pen o = p;
o.Color = Color.White;
}

or

Pen o = p;
{
o.Color = Color.White;
}

if you want.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: VB.Net With Statement by Gabriele

Gabriele
Fri Apr 16 09:24:36 CDT 2004

My intent was more to give an aesthetical equivalent, but yes - your
suggestions are better than mine.



Re: VB.Net With Statement by doknjas

doknjas
Fri Apr 16 11:10:10 CDT 2004

> You can get something close with the with the C# using keyword

I can't believe how many times I've heard someone say that (the
'second' use of) "using" in C# is somehow similar to VB's "With". As
Jon says, there is absolutely nothing that relates the two concepts.
I could understand a confusion if a "using" block allowed you to omit
the object reference, but that's not the case.


Re: VB.Net With Statement by Gabriele

Gabriele
Fri Apr 16 12:32:51 CDT 2004

>there is absolutely nothing that relates the two concepts.

I somewhat disagree. The way that the VB.BET compiler handles the With
statement is to create a hidden local of the same type, assign a reference
to the object, and use the temporary local for the subsequential calls
within the With/End With block.

The solutions that Jon proposed mimic this approach.



re:VB.Net With Statement by doknjas

doknjas
Fri Apr 16 14:07:42 CDT 2004

I'm confused now - Jon's code didn't use "using" at all.

The fact remain:

With X
....
End With

has exactly nothing to do with what is happening in:

using (X)
{
...
}


Re: re:VB.Net With Statement by Gabriele

Gabriele
Fri Apr 16 14:32:02 CDT 2004

> I'm confused now - Jon's code didn't use "using" at all.

As I said in response to his post, his suggestion was better then using the
"using" keyword. So you're right too. My comment was more from the
theoretical point of view. I apologize for the confusion that I may have
created.



Re: VB.Net With Statement by Jiri

Jiri
Fri Apr 16 16:02:05 CDT 2004

The C# literature recomend this:

object o = my.data.object
....
o.actionOne;
o.property = value;
...

and this works quite well.

Pazu

"Rob Shorney" <fred.flintstone@bedrock.com> pí¹e v diskusním pøíspìvku
news:Oi4eZg4IEHA.3308@tk2msftngp13.phx.gbl...
> Hi,
>
> Please could someone let me know if there is a equivalent command for C#
>
> ie
> vb.net
>
> with object
> .
> .
> .
> end with
>
>