I have noticed there are other threads on global variables in c#. Such as integers, strings etc. e.g.
public static int;
But I need to use a “var” which the other thread don’t mention and
public static var;
doesn’t seem to work.
So what I’m asking is it possible to have a “var” as a global variable in c#?
C# specification (section 26.1) reads:
It goes further:
So no, you cannot do this. Moreover I would recommend steering away from even thinking about global variables.
Global variables are not supported by the language. You may find alternatives in
public staticfields, but this will leak object state and break encapsulation.