Quantcast
Channel: Questions in topic: "static variables"
Viewing all articles
Browse latest Browse all 84

Static variable inside a function like in C ?

$
0
0
In C lang I could do something like this: void f() { static int a = 0; printf("%d\n", a); a++; } Calling this function 3 times would result in: 0 1 2 Is it possible to use static variables like this in C# ? In other words, to make, somehow, a variable inside a function persistent, until the next call. I know I could use global variables, but I would like to keep my code cleaner and less confusing.

Viewing all articles
Browse latest Browse all 84

Trending Articles