Static members are frequently used as counters. : Static : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Static »

 

Static members are frequently used as counters.








    
 

using System;

public class Starter {
    public static void Main() {
        MyClass<int> obj1 = new MyClass<int>();
        MyClass<double> obj2 = new MyClass<double>();
        MyClass<double> obj3 = new MyClass<double>();
        MyClass<int>.Count(obj1);
        MyClass<double>.Count(obj2);
    }
}

public class MyClass<T> {

    public MyClass() {
        ++counter;
    }

    public static void Count(MyClass<T> _this) {
        Console.WriteLine("{0} : {1}",
            _this.GetType().ToString(),
            counter.ToString());
    }

    private static int counter = 0;
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Static