473,387 Members | 1,899 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,387 software developers and data experts.

With or not with keyword

In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
..text = "This"
..enabled=true
..maxLength = 11
end with

Is there anyting like this in C#

Nov 17 '05 #1
8 1202
Hi,

No , only aliases for namespaces like

using MyAlias = System.Text;

MyAlias.StringBuilder;

that's all,
cheers
Salva

"John S" wrote:
In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
..text = "This"
..enabled=true
..maxLength = 11
end with

Is there anyting like this in C#

Nov 17 '05 #2
No, there is no such construct in C# and I believe in VB.NET neither. 'With'
is considered to make the code harder to read

"John S" <jo********@cinfin.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
.text = "This"
.enabled=true
.maxLength = 11
end with

Is there anyting like this in C#

Nov 17 '05 #3
It's not in C# but in VB.NET it is. And it doesn't make the code harder to
read.
It even makes it easier to write little faster code.

TextBox1.Text = "This";
TextBox1.Enabled = true;
.....

would each time call the get accessor of the TextBox1-Property (if its not a
field) wich can have a little performance impact.

The with construct makes something like:
TextBox t = TextBox1;
t.Text = "This";
t.Enabled = true;
......
t = null;

imho the with statement is easier to read and to type and in most cases it's
(a bit) faster.
this is one of the few VB-features i would like to have in c#

Christof

"Lebesgue" <no****@spam.jp> schrieb im Newsbeitrag
news:uO**************@TK2MSFTNGP15.phx.gbl...
No, there is no such construct in C# and I believe in VB.NET neither.
'With'
is considered to make the code harder to read

"John S" <jo********@cinfin.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
.text = "This"
.enabled=true
.maxLength = 11
end with

Is there anyting like this in C#


Nov 17 '05 #4

"Lebesgue" <no****@spam.jp> wrote in message
news:uO**************@TK2MSFTNGP15.phx.gbl...
No, there is no such construct in C# and I believe in VB.NET neither.
'With'
is considered to make the code harder to read

"John S" <jo********@cinfin.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
.text = "This"
.enabled=true
.maxLength = 11
end with

Is there anyting like this in C#



Works fine in VB.Net :)

Mythran

Nov 17 '05 #5
See
http://www.gotdotnet.com/team/csharp.../ask.aspx#with

John S wrote:
In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
.text = "This"
.enabled=true
.maxLength = 11
end with

Is there anyting like this in C#

Nov 17 '05 #6
John S <jo********@cinfin.com> wrote:
In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
.text = "This"
.enabled=true
.maxLength = 11
end with

Is there anyting like this in C#


No. You can always use a single-character variable name if you want. It
has the same effect, other than being *slightly* easier to read.
(Alternatively, use a meaningful name and keep readability high.)

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

"Christof Nordiek" <cn@nospam.de> wrote in message
news:OC**************@TK2MSFTNGP14.phx.gbl...
It's not in C# but in VB.NET it is. And it doesn't make the code harder to
read.
It even makes it easier to write little faster code.

TextBox1.Text = "This";
TextBox1.Enabled = true;
....

would each time call the get accessor of the TextBox1-Property (if its not
a field) wich can have a little performance impact.

The with construct makes something like:
TextBox t = TextBox1;
t.Text = "This";
t.Enabled = true;
.....
t = null;

imho the with statement is easier to read and to type and in most cases
it's (a bit) faster.
this is one of the few VB-features i would like to have in c#

Christof

This was true in VB6 (the little faster code) but it isn't any longer in
managed code.
IMO it was the correct decision not to include it. It might be easier to
read for those used to VB, but these were not the developers MS was
targeting at when they designed C#. Those who aren't used to the construct
might find it less readable.

Willy.
Nov 17 '05 #8
Jon Skeet [C# MVP] wrote:
John S <jo********@cinfin.com> wrote:
In Visual Basic, there was a keyword called "With". If you referenced
an object with the keyword With you could access all properties and
events just using the "." and not having to use the object name.
Example
With TextBox1
.text = "This"
.enabled=true
.maxLength = 11
end with

Is there anyting like this in C#

No. You can always use a single-character variable name if you want. It
has the same effect, other than being *slightly* easier to read.
(Alternatively, use a meaningful name and keep readability high.)


Or name what you are doing "with" a particular instance ie use a method
Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keith Morris | last post by:
Hi all! I'm creating a mini CMS that will store content in a MySQL database. What I am trying to do is parse the content and replace certain keywords with a link. The keywords and associated...
1
by: Evan | last post by:
Hi guys, I have a database table (documents) with a structure that looks like this: docID docName keyWords 1 testTitle01.doc dog,cat,bob 2 testTitle02.doc ...
4
by: infiniti | last post by:
Hi, I am coming across problems in trying to EFFICIENTLY merge to XML files into one which involves transposing the rows into columns so that I can either generate a single flat xml file or store...
4
by: tzellman | last post by:
Ok, so here is my situation: Let's assume I have a function that makes good use of the kwargs parameter. It requires that there is a certain "format" for the kwargs keywords. (I am using Django,...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
18
by: vermarajeev | last post by:
Hello everybody, This is my second query in this post. Firstly thankx to Banfa, for helping me solve my first query. Here is the code which I have written. #include<iostream>...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
2
by: rlemusic | last post by:
Hi everybody, I’m creating a database in Access (I believe it’s 2000) to catalogue items in the archives of a small museum. I’m a total n00b as far as using Access goes, but by looking at some...
2
by: pjamrisk | last post by:
Hi, I was wondering if one of the many guru's my help me out. Through several javascript books we have been trying to make an autocomplete feature for our department website for certain fields from...
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.