471,337 Members | 1,133 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

VB's With keyword

Hi,
Is there a C# equivelant to VB's with keyword?

Thanks,
Tim.
Feb 21 '06 #1
10 1514
Hi Timothy,
nope, no such equivalent for VB's with statement in C#.

Mark.
--
http://www.markdawson.org
"Timothy V" wrote:
Hi,
Is there a C# equivelant to VB's with keyword?

Thanks,
Tim.

Feb 21 '06 #2
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Hi Timothy,
nope, no such equivalent for VB's with statement in C#.


Good ridence I say :-)

Michael
Feb 21 '06 #3
"Michael C" <no****@nospam.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Hi Timothy,
nope, no such equivalent for VB's with statement in C#.


Good ridence I say :-)


Agree 100%
Feb 21 '06 #4
"With" is considered by many to be poor programming practice because it
obscures the contained code purely for the benefit of reduced typing of one
object name during development (have you ever tried to see what object you're
"With"ing in the middle of a long "With"? - you can't) .

If you want to simulate "With", then you can use abbreviated variable names,
but this has also obscures your code (but it can be applied to more than one
object at the same time, while "With" can't).

Another alternative is to refactor so that what you were "With"ing is a new
method where you then can reduce the variable name length (without making it
obscure).

--
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

"Timothy V" wrote:
Hi,
Is there a C# equivelant to VB's with keyword?

Thanks,
Tim.

Feb 21 '06 #5
On Tue, 21 Feb 2006 07:47:11 -0000, "Mark Rae" <ma**@markN-O-S-P-A-M.co.uk>
wrote:
"Michael C" <no****@nospam.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Hi Timothy,
nope, no such equivalent for VB's with statement in C#.


Good ridence I say :-)


Agree 100%

Yep!

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Feb 22 '06 #6
rkc
Michael C wrote:
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Hi Timothy,
nope, no such equivalent for VB's with statement in C#.

Good ridence I say :-)

Michael


Care to explain why "Good ridence I say"?
Feb 23 '06 #7
"rkc" <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in message
news:NE*******************@twister.nyroc.rr.com...
Michael C wrote:
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Hi Timothy,
nope, no such equivalent for VB's with statement in C#.

Good ridence I say :-)

Michael


Care to explain why "Good ridence I say"?


It makes the code less readable, it appears as an indented block but it's
not a block, it makes searching in your code difficult and it is actually
slower (it's a myth that it's faster).

Michael
Feb 26 '06 #8
The With keyword, like anything else, is a tool that can be used wisely
or unwisely. I think it can increase or decrease readability,
depending on how it's used. Although I don't use it much myself, I do
think that as a shortcut for initializing many properties of an object,
it's very useful and its use results in more readable code than
referencing the same variable over and over.

"it is actually slower (it's a myth that it's faster). "
Can you please point me to a benchmark or article that proves it? Just
an educated guess, but I would speculate that the With keyword compiles
to close to the same, if not identical, IL as multiple object
references.

Thanks,
Jared

Feb 26 '06 #9
"JaredHite1" <ja***@sharingds.org> wrote in message
news:11**********************@t39g2000cwt.googlegr oups.com...
The With keyword, like anything else, is a tool that can be used wisely
or unwisely. I think it can increase or decrease readability,
depending on how it's used. Although I don't use it much myself, I do
think that as a shortcut for initializing many properties of an object,
it's very useful and its use results in more readable code than
referencing the same variable over and over.
These cases are very rare and I think it's better just to use the same
variable over and over in the case.
"it is actually slower (it's a myth that it's faster). "
Can you please point me to a benchmark or article that proves it? Just
an educated guess, but I would speculate that the With keyword compiles
to close to the same, if not identical, IL as multiple object
references.
I'm talking about With in vb6 as this was what the OP was talking about.
Every article you find will say that With is faster but this is not true.
I've been through this several times in newsgroups before. Obvious with will
be faster in this situation

A.B.C.DoSomething
A.B.C.DoSomething
A.B.C.DoSomething

Thanks,
Jared

Feb 27 '06 #10
oops... pushed ctrl-enter...

"JaredHite1" <ja***@sharingds.org> wrote in message
news:11**********************@t39g2000cwt.googlegr oups.com...
The With keyword, like anything else, is a tool that can be used wisely
or unwisely. I think it can increase or decrease readability,
depending on how it's used. Although I don't use it much myself, I do
think that as a shortcut for initializing many properties of an object,
it's very useful and its use results in more readable code than
referencing the same variable over and over.
These cases are very rare and I think it's better just to use the same
variable over and over in the case.
"it is actually slower (it's a myth that it's faster). "
Can you please point me to a benchmark or article that proves it? Just
an educated guess, but I would speculate that the With keyword compiles
to close to the same, if not identical, IL as multiple object
references.
I'm talking about With in vb6 as this was what the OP was talking about.
Every article you find will say that With is faster but this is not true.
I've been through this several times in newsgroups before. Obvious With will
be faster in this situation

A.B.C.DoSomething
A.B.C.DoSomething
A.B.C.DoSomething

With A.B.C
.DoSomething
.DoSomething
.DoSomething
End With

but it's not a valid comparison as the original code should have been

dim o as WhatEver
set o = A.B.C
o.DoSomething
o.DoSomething
o.DoSomething

I can't point you to any code or benchmarks because they will all say with
is faster, but if you try it you'll see otherwise.

Michael


Thanks,
Jared


Feb 27 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Saga | last post: by
10 posts views Thread by Özden Irmak | last post: by
25 posts views Thread by Siv | last post: by
12 posts views Thread by Shariq | last post: by
29 posts views Thread by Michael D. Ober | last post: by
7 posts views Thread by fniles | last post: by
10 posts views Thread by Timothy | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.