Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Quick, Easy C# Question - Use of this Keyword

Posted on 2007-03-29
Medium Priority
Last Modified: 2010-04-16
This may seem like a silly question but I can't remember what the difference is (if there is any) between calling a method this way: this.MethodName();

and this way MethodName();

In each case, the method is local.

As far as I know, these are equivalent.
Question by:marmaxx
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 32

Expert Comment

by:Daniel Wilson
ID: 18818600
No difference -- except that this.MethodName() must be public.  MethodName() can be private.
LVL 25

Accepted Solution

dstanley9 earned 200 total points
ID: 18818895
this.MethodName() can be used to access private methods as well...

Only difference is this.MethodName() cannot be used to access static methods.

Expert Comment

ID: 18819822
So, basically "this" refers to the particular -instance- of the class that the method is in. (so in case of a static method there would nto be an instance hence there would be no "this" .. )
LVL 32

Expert Comment

by:Daniel Wilson
ID: 18819847
>>Only difference is this.MethodName() cannot be used to access static methods.

Or is it that "this" cannot be used WITHIN a static method?
LVL 25

Assisted Solution

dstanley9 earned 200 total points
ID: 18819870
Both are true.  

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question