Reputation: 1099
I want to make a var variable that is accessible across all functions ? How can I make it I tried public var a but it gives error?
Upvotes: 0
Views: 84
Reputation: 1312
If you want to have the variable accessible across all methods in your call, you'll have to move it out of the method it's in and move it up to the class level. You can make in private to prevent other classes from getting to it, but you can't have a method variable available outside of that method.
Upvotes: 0
Reputation: 43056
The var
keyword is only available for local variables. Class-level fields must have their types explicitly declared.
Upvotes: 0
Reputation: 180858
The C# language is designed to sequester all such state variables inside of a class.
What you're probably looking for is a Singleton. Whether that's a good idea or not is an open question.
Upvotes: 3