How to use static variable in C#

1 Answer

0 votes
using System;

class Program
{
    static int counter = 0;
    
    static void f() {
        counter++;
        Console.WriteLine(counter);
    }
    
    static void Main()
    {
        f();
        f();
        f();
    }
}


/*
run:

1
2
3

*/

 



answered Apr 5, 2019 by avibootz

Related questions

1 answer 198 views
198 views asked Jul 18, 2014 by avibootz
1 answer 155 views
155 views asked Jan 22, 2025 by avibootz
2 answers 111 views
2 answers 97 views
97 views asked Jan 22, 2025 by avibootz
1 answer 109 views
2 answers 164 views
...