Follow

What is CS0120?

Symptoms

  • I am getting the error below appearing in my console:
error CS0120: An object reference is required to access non-static 
member `____'

Cause

There are a few causes of this and they are listed below:

1. This is caused when a static method is attempting to use a non-static variable by referencing it directly.

Error this example presents:

error CS0120: An object reference is required to access non-static 
member `MyScript.name'

2. This error is also generated when a non static method is called from a static method like so:

Error this example presents:

error CS0120: An object reference is required to access non-static 
member `MyScript.MethodB()'

Resolution

1. CS0120 can be solved by creating a reference to the non-static variable like so:

2.  CS0120 can be solved by creating a reference to the non-static method like so:

More Information

https://msdn.microsoft.com/en-us/library/s35hcfh7.aspx

 

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

1 Comments

  • 0
    Avatar
    tbsupercoder

    it does not help right now but could help in the next game I am making thanks

     

Please sign in to leave a comment.