Re: What is "this" ?



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:JohnWebbs@xxxxxxxxxxx]
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


.



Relevant Pages

  • Re: Please ignore
    ... >> My posts aren't showing up in the group for some reason. ... Try something other than outlook ... John ... Prev by Date: ...
    (comp.lang.php)
  • Re: No carbonation in stout - 12 days
    ... > I suppose 2 weeks in the secondary does not classify as a long ... If for some reason, it is still uncarbonated after two ... John. ... Prev by Date: ...
    (rec.crafts.brewing)
  • Re: OT: Republican on Republican Violence!!!
    ... Sounds like a good enough reason to me! ... John H ... "All decisions are the result of binary thinking." ... Prev by Date: ...
    (rec.boats)
  • Third (and last) day of Bcon pics
    ... I didn't take any pictures on Sunday, for some reason. ... In the pool. ... John P ... Prev by Date: ...
    (rec.arts.mystery)
  • What is "this" ?
    ... I know for sure that in c#, I donot need "this" and the thing still works ... Is there a very good reason to use "this" notation ... John ... Prev by Date: ...
    (microsoft.public.dotnet.framework.aspnet)