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