Interviews - C# Corner

Bala S
Is it possible to use "This" keyword in a static method?
By Bala S in .NET onOct 17 2018
  • Sreekanth Reddy
    Oct, 2018 26

    Basically "this" refers to the instance of the current class. So for a static class we cant create the instance. Hence we cant use.

    • 8
  • Bala S
    Oct, 2018 17

    we can't use "This" keyword in static method because we can able to use only static variable and methods.

    • 3
  • Mamta Rajpoot
    Oct, 2018 27

    No we cannot

    • 2
  • Neeraj Agnihotri
    Jan, 2019 30

    Direct answer to the question is NO, we can't use This keyword with static method. Explanation: The purpose of THIS keyword is to point to an instance of a class i.e. object. Ex. For class vehicle, CAR is an instance which can be pointed using THIS keyword. Where as STATIC defines something common to all instances and becomes a TYPE. If everything is same in all instances why would you need to make a NEW instance of it. and that's how there is no use of THIS with STATIC.

    • 1
  • Siddhesh Chalke
    Oct, 2018 29

    "This" referes to current instance of a class. Since Static method is class member compiler will get confused about which instance we are trying to access

    • 1
  • Gaurav Gupta
    Apr, 2019 24

    No, we can't use 'this' keyword inside the static method bcz static class doesn't have instance. we can use this keyword as first parameter in static method.

    • 0
  • Kapil Gaur
    Jan, 2019 30

    I would like to first tell. This keyword points to current object of a class. So If you cannot create object of a static class then how can you use this. So the simple answer is we cannot use 'This' keyword in static method.

    • 0
  • Sneha Reddy
    Dec, 2018 26

    Basically "This" keyword is used for the instance members. As static methods are directly accessed by the class name and the method name we cannot use "This" keyword for static members.

    • 0
  • Abhinav Singh
    Dec, 2018 21

    No.This refer to current instance.For Static class you can not create instance.

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS