using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
CountableInstance ctble0 = new CountableInstance();
CountableInstance ctble1 = new CountableInstance();
CountableInstance ctble2 = new CountableInstance();
Console.WriteLine("ctble0 index = " + ctble0.InstanceIndex);
Console.WriteLine("ctble1 index = " + ctble1.InstanceIndex);
Console.WriteLine("ctble2 index = " + ctble2.InstanceIndex);
Console.WriteLine("ctble0 index = " + ctble0.InstanceIndex);
Console.WriteLine("ctble2 index = " + ctble2.InstanceIndex);
public class CountableInstance : IDisposable
private static List<CountableInstance> instances = new List<CountableInstance>();
public CountableInstance()
InstanceIndex = instances.Count;
for(int i = InstanceIndex; i < instances.Count; i++)
instances[i].InstanceIndex = i;
public int InstanceIndex { get; private set; }