473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

"With" equivalent in C#

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
9 17755
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
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
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
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
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
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
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
<.> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mikito Harakiri | last post by:
I wonder if WITH RECURSIVE MaryAncestor(anc,desc) AS ( (SELECT parent as anc, child as desc FROM ParentOf WHERE desc = "Mary") UNION (SELECT A1.anc, A2.desc FROM MaryAncestor A1, MaryAncestor...
5
by: DrOrbit | last post by:
In Pascal/Delphi you can say With MyStructure do begin Field1 := something; Field2 := somethingElse; : // and so on... end; "With MyStructure" avoids having to prepend "MyStructure" to...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
9
by: Mr Flibble | last post by:
Is there an equivalent of VB's "with" statement in c# ?
6
by: sck10 | last post by:
Hello, Is there the equivalent of the "with" command in c#? protected void SetFocusControl(Control FocusControl) { System.Text.StringBuilder script = New System.Text.StringBuilder();...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
24
by: carnold | last post by:
Hello, I'm a developer coming from C++ and Java ... I've going thru "Effective C#" (which highly recommend for people coming from other languages wanting to learn C#), and it states that "value...
13
by: Steve | last post by:
On page 392 of "Javascript the definitive guide" a function is called like this:- <form action="processform.cgi" onsubmit="return validateForm();"> Why, in this instance, is the return...
1
by: Chuck Chopp | last post by:
I have some code that is being built on the following: Windows Server 2003, both 32-bit & 64-bit editions Windows Vista, both 32-bit & 64-bit editions Windows Server 2008, both 32-bit & 64-bit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.