3rd December 2019

c-sharpcorner
8

Can this be used within a static method?

The answer is no because static method does not need any object to be called, and this keyword always point to a current object of a class. simply if there is no object then how the keyword point to any current object so,we cannot use this keyword here.

In this regard, why do we use static in C#?

The static member is always accessed by the class name, not the instance name. Therefore, const fields can be accessed by using the same ClassName.MemberName notation that is used for static fields. No object instance is required. C# does not support static local variables (variables that are declared in method scope).

What is the use of static method?

If you apply static keyword with any method, it is known as static method. A static method belongs to the class rather than object of a class. A static method invoked without the need for creating an instance of a class. static method can access static data member and can change the value of it.

What is a static method in C#?

The Static Keyword. In C# terms, “static” means “relating to the type itself, rather than an instance of the type”. You access a static member using the type name instead of a reference or a value, e.g. Guid.NewGuid(). In addition to methods and variables, you can also declare a class to be static (since C# 2.0).
Write Your Answer

Rate

100% people found this answer useful, click to cast your vote.

5 / 5 based on 1 vote.

Bookmark

Press Ctrl + D to add this site to your favorites!

Share