Solved

Quick, Easy C# Question - Use of this Keyword

Posted on 2007-03-29
5
168 Views
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.
0
Comment
Question by:marmaxx
  • 2
  • 2
5 Comments
 
LVL 32

Expert Comment

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

Accepted Solution

by:
dstanley9 earned 50 total points
Comment Utility
this.MethodName() can be used to access private methods as well...

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

Expert Comment

by:Nico
Comment Utility
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" .. )
0
 
LVL 32

Expert Comment

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

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

Assisted Solution

by:dstanley9
dstanley9 earned 50 total points
Comment Utility
Both are true.  
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now