By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

"With" equivalent in C#

P: n/a
Hello

I am new both to this group and to C# programming having spent the last 15
years or so writing C and VB.

You will forgive I hope if I am asking the totally obvious but it is a
question that I cannot find an answer to in the doc:

Is there an equivalent in C# to the "With Me" syntax in VB; specifically
some means of getting a down-down that enumerates the objects available on a
form instead of having to remember them or having to go look what's there?

Thanks

Paul BJ
Nov 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Unfortunately, no I don't believe there is. In the old days of VB, with
could provide significant performance enhancements every time you cut out a
'.' which other than readability, was it's primary allure. However, from
what I've been told, that's no longer the case. Anyway, I agree it's a nice
construct, but I don't believe there's a C# equivalent.
"Paul Brownjohn" <pa*************@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hello

I am new both to this group and to C# programming having spent the last 15
years or so writing C and VB.

You will forgive I hope if I am asking the totally obvious but it is a
question that I cannot find an answer to in the doc:

Is there an equivalent in C# to the "With Me" syntax in VB; specifically
some means of getting a down-down that enumerates the objects available on a form instead of having to remember them or having to go look what's there?

Thanks

Paul BJ

Nov 15 '05 #2

P: n/a
No, there is no C# counterpart. And, according to C# dev blogs, it's not in
the plan for the foreseeable future either.
The equivalent code to "With
OriginalObjectRef.Property1.Property2.Indexer[5]" is to create a temp
reference:

MyClassType ref = OriginalObjectRef.Property1.Property2.Indexer[5];
ref.Prop1 = 100;
ref.Prop2 = "some text";
ref.Method1();

That keeps you from having to type the entire chain of members every time,
and is basically what VB comiles in the background.

If all you are worried about is the quick drop-down intellisense, just type
"this."
Yes, it's not as convenient as using With, but it's what you have.

-Rob Teixeira [MVP]

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Unfortunately, no I don't believe there is. In the old days of VB, with
could provide significant performance enhancements every time you cut out a '.' which other than readability, was it's primary allure. However, from
what I've been told, that's no longer the case. Anyway, I agree it's a nice construct, but I don't believe there's a C# equivalent.
"Paul Brownjohn" <pa*************@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hello

I am new both to this group and to C# programming having spent the last 15 years or so writing C and VB.

You will forgive I hope if I am asking the totally obvious but it is a
question that I cannot find an answer to in the doc:

Is there an equivalent in C# to the "With Me" syntax in VB; specifically
some means of getting a down-down that enumerates the objects available on
a
form instead of having to remember them or having to go look what's

there?
Thanks

Paul BJ


Nov 15 '05 #3

P: n/a
Or, if you want to save keystrokes and are in to cheap hacks that will
probably be unreadable to others, just declare a refernece and name it _ or
something.

{ // with
MyClassType _ = OriginalObjectRef.Property1.Property2.Indexer[5];
_.Prop1 = 100;
_.Prop2 = "some text";
_.Method1();
} // end with
Not that this is any less readable than the With construct, in my opinion.

*sheepish grin*

--Matthew W. Jackson

"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
No, there is no C# counterpart. And, according to C# dev blogs, it's not in the plan for the foreseeable future either.
The equivalent code to "With
OriginalObjectRef.Property1.Property2.Indexer[5]" is to create a temp
reference:

MyClassType ref = OriginalObjectRef.Property1.Property2.Indexer[5];
ref.Prop1 = 100;
ref.Prop2 = "some text";
ref.Method1();

That keeps you from having to type the entire chain of members every time,
and is basically what VB comiles in the background.

If all you are worried about is the quick drop-down intellisense, just type "this."
Yes, it's not as convenient as using With, but it's what you have.

-Rob Teixeira [MVP]

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Unfortunately, no I don't believe there is. In the old days of VB, with
could provide significant performance enhancements every time you cut out
a
'.' which other than readability, was it's primary allure. However, from what I've been told, that's no longer the case. Anyway, I agree it's a nice
construct, but I don't believe there's a C# equivalent.
"Paul Brownjohn" <pa*************@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hello

I am new both to this group and to C# programming having spent the last 15 years or so writing C and VB.

You will forgive I hope if I am asking the totally obvious but it is a
question that I cannot find an answer to in the doc:

Is there an equivalent in C# to the "With Me" syntax in VB;
specifically some means of getting a down-down that enumerates the objects
available on
a
form instead of having to remember them or having to go look what's

there?
Thanks

Paul BJ



Nov 15 '05 #4

P: n/a
Paul Brownjohn <pa*************@skynet.be> wrote:
I am new both to this group and to C# programming having spent the last 15
years or so writing C and VB.

You will forgive I hope if I am asking the totally obvious but it is a
question that I cannot find an answer to in the doc:

Is there an equivalent in C# to the "With Me" syntax in VB; specifically
some means of getting a down-down that enumerates the objects available on a
form instead of having to remember them or having to go look what's there?


Others have given responses to the rest of the "with" debate, but to
address your last point - if you just want to get a drop-down, type
"this." and the members should all show up.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5

P: n/a
You will have alises for namespaces in 2.0 and if you dont want to type alot
you can take a local reference to shorten the list.
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
No, there is no C# counterpart. And, according to C# dev blogs, it's not in the plan for the foreseeable future either.
The equivalent code to "With
OriginalObjectRef.Property1.Property2.Indexer[5]" is to create a temp
reference:

MyClassType ref = OriginalObjectRef.Property1.Property2.Indexer[5];
ref.Prop1 = 100;
ref.Prop2 = "some text";
ref.Method1();

That keeps you from having to type the entire chain of members every time,
and is basically what VB comiles in the background.

If all you are worried about is the quick drop-down intellisense, just type "this."
Yes, it's not as convenient as using With, but it's what you have.

-Rob Teixeira [MVP]

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Unfortunately, no I don't believe there is. In the old days of VB, with
could provide significant performance enhancements every time you cut out
a
'.' which other than readability, was it's primary allure. However, from what I've been told, that's no longer the case. Anyway, I agree it's a nice
construct, but I don't believe there's a C# equivalent.
"Paul Brownjohn" <pa*************@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hello

I am new both to this group and to C# programming having spent the last 15 years or so writing C and VB.

You will forgive I hope if I am asking the totally obvious but it is a
question that I cannot find an answer to in the doc:

Is there an equivalent in C# to the "With Me" syntax in VB;
specifically some means of getting a down-down that enumerates the objects
available on
a
form instead of having to remember them or having to go look what's

there?
Thanks

Paul BJ



Nov 15 '05 #6

P: n/a
That may help some in not "typing a lot", but it's really a completely
different concept than the VB "With" construct. One shortens acess to
types, the other shortens access to objects' members.

<.> wrote in message news:eX**************@TK2MSFTNGP09.phx.gbl...
You will have alises for namespaces in 2.0 and if you dont want to type alot you can take a local reference to shorten the list.
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
No, there is no C# counterpart. And, according to C# dev blogs, it's not

in
the plan for the foreseeable future either.
The equivalent code to "With
OriginalObjectRef.Property1.Property2.Indexer[5]" is to create a temp
reference:

MyClassType ref = OriginalObjectRef.Property1.Property2.Indexer[5];
ref.Prop1 = 100;
ref.Prop2 = "some text";
ref.Method1();

That keeps you from having to type the entire chain of members every time,
and is basically what VB comiles in the background.

If all you are worried about is the quick drop-down intellisense, just

type
"this."
Yes, it's not as convenient as using With, but it's what you have.

-Rob Teixeira [MVP]

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Unfortunately, no I don't believe there is. In the old days of VB, with could provide significant performance enhancements every time you cut out
a
'.' which other than readability, was it's primary allure. However,

from what I've been told, that's no longer the case. Anyway, I agree it's a nice
construct, but I don't believe there's a C# equivalent.
"Paul Brownjohn" <pa*************@skynet.be> wrote in message
news:40*********************@news.skynet.be...
> Hello
>
> I am new both to this group and to C# programming having spent the last
15
> years or so writing C and VB.
>
> You will forgive I hope if I am asking the totally obvious but it is

a > question that I cannot find an answer to in the doc:
>
> Is there an equivalent in C# to the "With Me" syntax in VB;

specifically > some means of getting a down-down that enumerates the objects

available
on
a
> form instead of having to remember them or having to go look what's

there?
>
> Thanks
>
> Paul BJ
>
>



Nov 15 '05 #7

P: n/a
Use a 1 letter reference, how hard is that?

DooferFangle d = blah.blah.blah;

Yeah very hard.
"Philip Rieck" <st***@mckraken.com> wrote in message
news:Oy**************@tk2msftngp13.phx.gbl...
That may help some in not "typing a lot", but it's really a completely
different concept than the VB "With" construct. One shortens acess to
types, the other shortens access to objects' members.

<.> wrote in message news:eX**************@TK2MSFTNGP09.phx.gbl...
You will have alises for namespaces in 2.0 and if you dont want to type alot
you can take a local reference to shorten the list.
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
No, there is no C# counterpart. And, according to C# dev blogs, it's not
in
the plan for the foreseeable future either.
The equivalent code to "With
OriginalObjectRef.Property1.Property2.Indexer[5]" is to create a temp
reference:

MyClassType ref = OriginalObjectRef.Property1.Property2.Indexer[5];
ref.Prop1 = 100;
ref.Prop2 = "some text";
ref.Method1();

That keeps you from having to type the entire chain of members every time, and is basically what VB comiles in the background.

If all you are worried about is the quick drop-down intellisense, just

type
"this."
Yes, it's not as convenient as using With, but it's what you have.

-Rob Teixeira [MVP]

"William Ryan" <do********@nospam.comcast.net> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
> Unfortunately, no I don't believe there is. In the old days of VB, with > could provide significant performance enhancements every time you
cut
out
a
> '.' which other than readability, was it's primary allure. However,

from
> what I've been told, that's no longer the case. Anyway, I agree

it's a nice
> construct, but I don't believe there's a C# equivalent.
> "Paul Brownjohn" <pa*************@skynet.be> wrote in message
> news:40*********************@news.skynet.be...
> > Hello
> >
> > I am new both to this group and to C# programming having spent the last
15
> > years or so writing C and VB.
> >
> > You will forgive I hope if I am asking the totally obvious but it
is a > > question that I cannot find an answer to in the doc:
> >
> > Is there an equivalent in C# to the "With Me" syntax in VB;

specifically
> > some means of getting a down-down that enumerates the objects

available
on
> a
> > form instead of having to remember them or having to go look

what's there?
> >
> > Thanks
> >
> > Paul BJ
> >
> >
>
>



Nov 15 '05 #8

P: n/a
<.> wrote in news:OL*************@TK2MSFTNGP12.phx.gbl:
Use a 1 letter reference, how hard is that?

DooferFangle d = blah.blah.blah;


Which is what most C++ programmers do and have done for years in conjunction
with local block variables.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 15 '05 #9

P: n/a
It's not difficult. I stated that namespace aliase and the With keyword are
orthagonal concepts, not that typing was difficult.

<.> wrote in message news:OL*************@TK2MSFTNGP12.phx.gbl...
Use a 1 letter reference, how hard is that?

DooferFangle d = blah.blah.blah;

Yeah very hard.
"Philip Rieck" <st***@mckraken.com> wrote in message
news:Oy**************@tk2msftngp13.phx.gbl...
That may help some in not "typing a lot", but it's really a completely
different concept than the VB "With" construct. One shortens acess to
types, the other shortens access to objects' members.

<.> wrote in message news:eX**************@TK2MSFTNGP09.phx.gbl...
You will have alises for namespaces in 2.0 and if you dont want to type
alot
you can take a local reference to shorten the list.
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
> No, there is no C# counterpart. And, according to C# dev blogs, it's not in
> the plan for the foreseeable future either.
> The equivalent code to "With
> OriginalObjectRef.Property1.Property2.Indexer[5]" is to create a
temp > reference:
>
> MyClassType ref = OriginalObjectRef.Property1.Property2.Indexer[5];
> ref.Prop1 = 100;
> ref.Prop2 = "some text";
> ref.Method1();
>
> That keeps you from having to type the entire chain of members every time,
> and is basically what VB comiles in the background.
>
> If all you are worried about is the quick drop-down intellisense, just type
> "this."
> Yes, it's not as convenient as using With, but it's what you have.
>
> -Rob Teixeira [MVP]
>
> "William Ryan" <do********@nospam.comcast.net> wrote in message
> news:O$**************@TK2MSFTNGP11.phx.gbl...
> > Unfortunately, no I don't believe there is. In the old days of VB,
with
> > could provide significant performance enhancements every time you

cut out
> a
> > '.' which other than readability, was it's primary allure.
However, from
> > what I've been told, that's no longer the case. Anyway, I agree

it's
a
> nice
> > construct, but I don't believe there's a C# equivalent.
> > "Paul Brownjohn" <pa*************@skynet.be> wrote in message
> > news:40*********************@news.skynet.be...
> > > Hello
> > >
> > > I am new both to this group and to C# programming having spent the last
> 15
> > > years or so writing C and VB.
> > >
> > > You will forgive I hope if I am asking the totally obvious but

it is
a
> > > question that I cannot find an answer to in the doc:
> > >
> > > Is there an equivalent in C# to the "With Me" syntax in VB;
specifically
> > > some means of getting a down-down that enumerates the objects
available
> on
> > a
> > > form instead of having to remember them or having to go look

what's > there?
> > >
> > > Thanks
> > >
> > > Paul BJ
> > >
> > >
> >
> >
>
>



Nov 15 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.