List Info

Thread: C-Sharp (C#) Group: Re: To "this" or not to "this" that is the question




C-Sharp (C#) Group: Re: To "this" or not to "this" that is the question
user name
2006-02-16 22:10:41
First and foremost, look to company coding standards.  After that, look to your own personal preferences.  The one and only reason I personally use "this" is for speed of typing.  When you use "this", you can access the members of the class immediately with Intellisense, and I see a dramatic increase in code completion.

Think of a class that has a member called longVariableName, and you want to access a property of that member called Something.  It is much faster using Intellisense to type:

this.longVariableName.Something

than it is to type:

longVariableName.Something

A point to make is that a lot of this is moot with VS2005, as intellisense is a lot smarter and it will help you with completion with or without using "this".  Aside from that, I would say to be consistent with how you do it, and don't keep switching back and forth.

On 2/16/06, SteveM <philips.com">steve.moodyphilips.com> wrote:

Yes I am new to the world of C# and .NET and yes this is probably a
heavily debated question (or not) but inquiring minds want to know so
here it goes.

I have read a few Coding Standards documents that state that use of the
this as in this.method() is greatly over-rated and infact should be
discouraged. So the real question here is, when is it appropriate to
use the "this" construct and what is the test to determine it use or
non use as the case may be. I thought I understood that its ok to use
(and even preferable) inside constructors but that its not really all
that useful in other places (methods for instance). So can some of you
guru's and wise people give me an answer. I would appreciate it. Oh by
the way if there is a FAQ please point me to it, I looked and was
unable to locate it.
Thanks in advance for your help
-SteveM



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: To "this" or not to "this" that is the question
user name
2006-02-16 22:43:11
Thanks Marty  Good
points all. I am kind of in the position of
helping to define or at least adopt our group's coding
standard, and
wanted to be sure that I wasn't steering anyone wrong. We
are using
2005 so I am advocating NOT using it 
Thanks again
-SteveM


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: To "this" or not to "this" that is the question
user name
2006-02-17 00:40:35
Hey Marty:

There is a neat trick in VS 2003, especially for people like
us who
live by the intellisense.

You mentioned that,  It is much faster using Intellisense to
type:
this.longVariableName.Something
than it is to type:
longVariableName.Something

Instead, just type in
longVariaria CTRL + SPACE
and you will get the intellisense pop up.

As for the coding guidelines, here is an MSDN article on
naming
guidelines
http://m
sdn.microsoft.com/library/default.asp?url=/library/en-us/cpg
enref/html/cpconnamingguidelines.asp


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )