473,394 Members | 2,031 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,394 software developers and data experts.

Simple question on CSharp style

Dom
Can I have a consensus. Is it common to start every variable,
control, etc, with "this"? I tend to do it, because I like the
Intellisense window. But is it considered amaturish?

Told you it was a simple question.

May 5 '07 #1
8 1149
Hi,
If you wanna have intellisense just press ctrl-space at the beggining
of the line :)
I don't use the "this" at least it's really needed.

Bye,
Diego

May 5 '07 #2
Dom wrote:
Can I have a consensus. Is it common to start every variable,
control, etc, with "this"? I tend to do it, because I like the
Intellisense window. But is it considered amaturish?

Told you it was a simple question.
IMHO, only use "this" if it helps to make code more readable, or if it's
needed. I'd consider constantly using "this" to be amaturish - it's the
curse of intellisense.
As Diego says, you can use Ctrl+Space to bring up the intellisense window.

Alun Harford
May 5 '07 #3
Dom wrote:
Can I have a consensus. Is it common to start every variable,
control, etc, with "this"? I tend to do it, because I like the
Intellisense window. But is it considered amaturish?
It is not not common to use it for everything.

But if you have the need to do it (because an argument is
shadowing for a field), then I tend to use it for all the
lines in the block.

Arne
May 6 '07 #4
I'm probably contrarian on this (pun intended), but I generally use
"this." explicitly for references to member fields, because it helps to
distinguish fields from variables. To me, it's just a way to make code
more self-evident. I don't like coming across a reference and having to
waste cycles figuring out / remembering if it's a field or not.

I don't bother doing this with methods, however, because there is no
need to distinguish whether a method is in the current class or not.
Inherently, a method call to another class is prefixed with an instance
variable, so any method call that's not thusly prefixed is part of the
current hierarchy scope.

When it comes to static methods, I always use the class prefix even if
I'm calling a static method from an instance method in the same class;
again, just to make the code more self-evident.

The operative principle here IMO is that it's harder to read code than
to write code. So make it easy to read. You save time and effort in
the long run.

--Bob

Dom wrote:
Can I have a consensus. Is it common to start every variable,
control, etc, with "this"? I tend to do it, because I like the
Intellisense window. But is it considered amaturish?

Told you it was a simple question.
May 6 '07 #5
FWIW, Resharper likes to "clean up" what it lovingly refers to as "redundant
this references".

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Dom" wrote:
Can I have a consensus. Is it common to start every variable,
control, etc, with "this"? I tend to do it, because I like the
Intellisense window. But is it considered amaturish?

Told you it was a simple question.

May 6 '07 #6
I find the "_" prefix more readable than "this" for fields.
May 7 '07 #7
I do the same as Bob. One more vote for the contrarians!

On May 5, 8:37 pm, Bob Grommes <b...@bobgrommes.comwrote:
I'm probably contrarian on this (pun intended), but I generally use
"this." explicitly for references to member fields, because it helps to
distinguish fields from variables. To me, it's just a way to make code
more self-evident. I don't like coming across a reference and having to
waste cycles figuring out / remembering if it's a field or not.

I don't bother doing this with methods, however, because there is no
need to distinguish whether a method is in the current class or not.
Inherently, a method call to another class is prefixed with an instance
variable, so any method call that's not thusly prefixed is part of the
current hierarchy scope.

When it comes to static methods, I always use the class prefix even if
I'm calling a static method from an instance method in the same class;
again, just to make the code more self-evident.

The operative principle here IMO is that it's harder to read code than
to write code. So make it easy to read. You save time and effort in
the long run.

--Bob

Dom wrote:
Can I have a consensus. Is it common to start every variable,
control, etc, with "this"? I tend to do it, because I like the
Intellisense window. But is it considered amaturish?
Told you it was a simple question.- Hide quoted text -

- Show quoted text -

May 7 '07 #8
I'm with Mark. I think the underscore creates more readable code.

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets
"Mark Wilden" <mw*****@communitymtm.comwrote in message
news:u6**************@TK2MSFTNGP05.phx.gbl...
>I find the "_" prefix more readable than "this" for fields.

May 8 '07 #9

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

Similar topics

1
by: matthias | last post by:
hello everybody ! i want to use the microsoft platform sdk c++ functions of the npp to capture data from network with visual studio .net and csharp. how can i import the c++ headers files to use...
2
by: andrewcw | last post by:
Seems it should be simple. I had problems with a larger class and the newsgroup suggested something I also tried. So I pruned my class to see if I could find out what could be wrong, Still dont...
2
by: anand | last post by:
Hi All, Are ownerdraw buttons supported in C# ? I have an active X control which I would like to use in CSharp. Buttons have a style BS_OWNERDRAW, and to do custom drawing you have to...
3
by: Peter | last post by:
Hello Thanks for reviewing my question. I would like to know how can I programmatically select a node Thanks in Advanc Peter
1
by: Preston | last post by:
hello all... My friend using vb.net made a DLL file which contains a Property Kkk(ByVal key As Object) in it, I use CSharp and reference this DLL file, but in csharp object browser, there is no...
5
by: Le, Thanh-Nhan | last post by:
Hi, I want to send a simple mail with C#. I have tried the following, but they don't work: - some solutions on CodeProject websites. - shellExecute(mailto:xxx@yyy.com?subject=aaa&body=bbb). ...
5
by: Sabari | last post by:
Hi, Im looking for an object oriented project in CSharp.All the projects that i come across use the old coding style where in they use asp style coding.If any one have a project entirely oops...
3
by: ahjiang | last post by:
Hi all, Is there any other controls in CSharp that is exactly the same as datagrid? Datagrid looks boring with the same old grey columns style. Appreciate any advice.
5
by: Joel | last post by:
In the course of my project, I must include some custom logic and would like to integrate a small script language in my application for that purpose. In C++, I used the LUA script language and I...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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.