What Is The Relation between this keyword and static method ?

Posted by Kasani007 under C# on 8/11/2014 | Points: 10 | Views : 1190 | Status : [Member] | Replies : 2
What Is The Relation between this keyword and static method ?




Responses

Posted by: Manimaddu on: 8/11/2014 [Member] Starter | Points: 25

Up
0
Down
Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier but if is not because if is a keyword.

Static methods have no instances. They are called with the type name, not an instance identifier. They are slightly faster than instance methods because of this. Static methods can be public or private.

Thanks & Regards,
Mani Kumar

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 8/12/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
keyword 'this' cannot be used in a static method.
The this keyword refers to the current instance of the class. Static member functions do not have a this pointer.

On the other hand, by using the combination of 'this' and static method, c# extension methods concept can be achieved.
An extension method is a static method of a static class that can be invoked using the instance method syntax.
please refer below url which decribes extension methods concept.
http://weblogs.asp.net/scottgu/new-orcas-language-feature-extension-methods

Thank you,
Govind

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response