S
Samuel R. Neff
Is there any way to declare a static variable within a generic type
definition and have that variable be shared across all constructed
generic types?
For example, how can I modify this code:
private class C<T>
{
public static int Counter = 0;
}
public static void Test()
{
Console.WriteLine(++C<int>.Counter);
Console.WriteLine(++C<string>.Counter);
Console.WriteLine(++C<double>.Counter);
}
Which prints out
1
1
1
To instead print out
1
2
3
Thanks,
Sam
definition and have that variable be shared across all constructed
generic types?
For example, how can I modify this code:
private class C<T>
{
public static int Counter = 0;
}
public static void Test()
{
Console.WriteLine(++C<int>.Counter);
Console.WriteLine(++C<string>.Counter);
Console.WriteLine(++C<double>.Counter);
}
Which prints out
1
1
1
To instead print out
1
2
3
Thanks,
Sam