Bala S
Is it possible to use "This" keyword in a static method?
By Bala S in .NET on Oct 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.

    • 9
  • 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
  • anil penumacha
    Jun, 2021 4

    I think Yea we can use This in parameter for static method. For implementing the extension methods we use “This” in parameters.

    Ex :
    public static class ExtMetClass
    {
    public static int IntegerExtension(this string str)
    {
    return Int32.Parse(str);
    }
    }

    • 0
  • Sudheshwer  Rai
    Apr, 2020 14

    According to me you can use “this” keyword only with static method parameter but there is certain condition like class and method must be static and this method will be called extension method.

    Visit - www.sudheshwertech.com for online dot net training. Thanks

    • 0
  • 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 Job Functions


MOST LIKED QUESTIONS