What is "this" ?

  • Thread starter Thread starter WJ
  • Start date Start date
W

WJ

What is "this" that is being used by many asp and asp.net web applications
and is there "that" object some where ? Googled what is that and was not
satisfied @ all !

I know for sure that in c#, I donot need "this" and the thing still works
correctly as expected ! Is there a very good reason to use "this" notation
on every line ?

John
 
Normally, you don't need "this", as C# prefixes "this." by default.

However, say you have a member variable and a local variable with the
same name:

class TheUseOfThis : IUntestedExample
{
private string a;

public void MyFunction()
{
string a;

this.a = "assigned to member var";
a = "assigned to local var";
}
}

As you can see you need this to assign to the member variable.

There is no that in C#, of course.

Greetings,
Wessel

-----Original Message-----
From: WJ [mailto:[email protected]]
Posted At: Sunday, April 10, 2005 3:50 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: What is "this" ?
Subject: What is "this" ?

What is "this" that is being used by many asp and asp.net web
applications
and is there "that" object some where ? Googled what is that and was not

satisfied @ all !

I know for sure that in c#, I donot need "this" and the thing still
works
correctly as expected ! Is there a very good reason to use "this"
notation
on every line ?

John
 
Thanks Wessel, that explains it. I better off use unique variables to avoid
being verbose and for ease of debugging..

John
 
:this" is a convenience, much like "using" which enables the developer to
omit namespaces. While it is generally not necessary, there are times when
conflicting names and namespaces make the use of "this" helpful. It can also
make your code easier to read.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Back
Top