Quick, Easy C# Question - Use of this Keyword

Posted on 2007-03-29
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 50 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 50 total points
ID: 18819870
Both are true.  

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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