newbie coming from vb: what happened to "with"?

  • Thread starter Thread starter Michael Maercker
  • Start date Start date
M

Michael Maercker

hi!

vb6 had a very useful "with...end with" construction... does c# have
anything similar?

thx,

mike
 
Michael Maercker said:
hi!

vb6 had a very useful "with...end with" construction... does c# have
anything similar?
No.
If you want to shorten the name of a long variable, it is generally
advisable to use a local with a short name, something like

ALongType o = ALongAccessString.Value;
o.DoSomething();


With has been a hotly debated topic(search google groups for some of the
threads), but will not likely ever make an appearance in C#.
 
vb6 had a very useful "with...end with" construction... does c# have
anything similar?


string myTooLongStringUsedOnlyHereAndNow = "hello world";

....

using (string s = myTooLongStringUsedOnlyHereAndNow)
{
Debug.Write (s);
}
 
Hi,

This has been discussed here A LOT, it cause more problems that the one it
solves. there is a very good explanation of why it was not included in
somebody from c# language team weblog , it's just I can't find it now :(



Ceers,
 
Jeti said:
string myTooLongStringUsedOnlyHereAndNow = "hello world";

...

using (string s = myTooLongStringUsedOnlyHereAndNow)
{
Debug.Write (s);
}

Actually, that won't work because string doesn't implement IDisposable.
However, there's no need for a using block:

string myTooLongStringUsedOnlyHereAndNow = "hello world":

{
string s = myToLongStringUsedOnlyHereAndNow;
Debug.Write(s);
}
 
'using' has nothing to do with the VB 'With'. It just happens to
appear to be similar visually. As Jon mentioned, it's not required.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Back
Top