Simple question on CSharp style

  • Thread starter Thread starter Dom
  • Start date Start date
D

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.
 
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
 
Dom said:
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
 
Dom said:
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
 
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
 
FWIW, Resharper likes to "clean up" what it lovingly refers to as "redundant
this references".

Peter
 
I'm with Mark. I think the underscore creates more readable code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Developing a simple IDE 2
ArrayList in CSharp 3
Spybot Anti-Beacon 3
Application variables in csharp. 4
Problem on loading a dialog box. 5
[Interop] Marshal of void** 3
Nest vs Hive? 10
System.Drawing.Graphics 1

Back
Top