Returns the current generation number of the target of a weak reference.
using System;
publicclass MainClass
{
staticvoid Main()
{
MainClass myGCCol = new MainClass();
WeakReference wkref = new WeakReference(myGCCol);
myGCCol = null;
Console.WriteLine("The WeakReference to the object is in generation: {0}", GC.GetGeneration(wkref));
GC.Collect();
}
}