Track instance count with static field.
Ready — edit the code above and click Run.
using System;
class Program
{
static void Main()
{
_ = new Student(); _ = new Student();
Console.WriteLine(Student.Count);
class Student {
public static int Count;
public Student() => Count++;
}
}
}
Try solving on your own first, then reveal the official answer.
Static members belong to the type, not instances.