Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there equivalents to "this" for static variables in c#

Tags:

c#

static

this

I was wondering if I can make my code clearer by indicating one variable is a static class variable. If it wasn't static I could use this.variableName, and everyone would look at it and immediately know that.

I know I could adopt a naming convention like s_variableName, but that seems a little odd to me and increases the learning curve of the code.

Is there an equivalent of "this" for static variables?

like image 664
Samuel Carrijo Avatar asked Jul 27 '09 10:07

Samuel Carrijo


People also ask

Can you use this on a static variable?

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. If you still, try to do so a compile time error is generated.

What can I use instead of a static variable?

Instance Variables: Instance variables are non-static variables and are declared in a class outside any method, constructor or block.

Can we change static variable value in C?

When static keyword is used, variable or data members or functions can not be modified again. It is allocated for the lifetime of program.

Are there static methods in C?

In C, functions are global by default. The “static” keyword before a function name makes it static. For example, below function fun() is static.


1 Answers

Qualify it with the type name:

TypeName.staticVariableName
like image 188
mmx Avatar answered Sep 22 '22 14:09

mmx