equivalent of with

  • Thread starter Thread starter Guest
  • Start date Start date
The simple answer is "Not". And I believe somebody in MS C# group
explained the reason why this is not implemented, you need google that.
 
| Did not find the reason but I hope they will add something like that in
the
| future.
|
| "John Sun" wrote:
|
| > The simple answer is "Not". And I believe somebody in MS C# group
| > explained the reason why this is not implemented, you need google that.
| >
| > Ofer wrote:
| > > What is the equivalent in C# for VB
| > > With <object>
| > >
| > > .something()
| > >
| > > End with
| >

The C# team and community at large already rejected this request, and it
looks like C# will not spoil another keyword for this. Of course you can
always try to make them change their minds by posting a suggestion to the
feedback center http://lab.msdn.microsoft.com

Willy.
 
This gets regular airings...

The main point is: why? it offers no significant benefit: with exactly the
same effort you could just do:

SomeClass instance = <object>; // your term... presumably accessed via a
property or function etc
instance.something();

And if you want to strictly scope the variable:

{
SomeClass instance = <object>; // your term... presumably accessed via a
property or function etc
instance.something();
}

It would honestly add very little...

This is very different to "using", "lock", etc, as these do offer a
significant benefit - both in terms of saved keystrokes and consistent
object access / disposal.

Marc
 
The beauty of the alternative demonstrated by Marc is that you can use it on
many objects at once, where the VB "With" can only be used on one object at a
time.

Another problem with "With" is that you lose the intellisense within a large
"With" block - you have to scroll to the top to see what you're "With"ing.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
Back
Top