Uttam Kumar
Why "this" Keyword cannot be used in a static method?

this keyword is used to refer to a class variable or method. When you declare static on a method the variable or method can be called without needing to instantiate an object of a class. Therefore this keyword is not allowed because your static method is not associated with any objects.

By Uttam Kumar in .NET on Feb 28 2022
  • Muhammad Imran Ansari
    Mar, 2022 17

    “this” (which is current class pointer) means current class OBJECT , so its clear that “this” only come in action once we create an Object of that class.

    In case of static method, we don’t create any object of class, we call static methods without instiation that’s why this not required with static.

    • 2
  • Rajeev Kumar
    Mar, 2023 17

    No, we can not used “this” keyword within a static method. because “this” keyword refers to the current instance of the class. Static Member functions do not have a this pointer (current instance). Note - we can also not used “base” keyword within a static method.

    • 1
  • Rajanikant Hawaldar
    Oct, 2022 13

    Because this points to an instance of the class, in the static method you don’t have an instance.

    • 1
  • saikiran Dubba
    Sep, 2023 25

    Output. The "this" keyword is used as a reference to an instance. Since the static methods doesn't have (belong to) any instance you cannot use the "this" reference within a static method.

    • 0
  • saikiran Dubba
    Sep, 2023 13

    The “this” keyword is used as a reference to an instance. Since the static methods doesn’t have (belong to) any instance you cannot use the “this” reference within a static method.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS