C# Generate Register Number Automatically for Students using Static Constructor

using System;

namespace staticprog
{
    class Sample
    {
        int regnumber;
        static int nextnum;

        static Sample()
        {
            nextnum = 1000;
        }

        Sample()
        {
            regnumber = ++nextnum;
        }

        public static void Main(string[] args)
        {
            Sample s = new Sample();
            Console.WriteLine("#1 : {0}", s.regnumber);

            s = new Sample();
            Console.WriteLine("#2 : {0}", s.regnumber);

            s = new Sample();
            Console.WriteLine("#3 : {0}", s.regnumber);

            Console.ReadLine();
        }
    }
}

 

Output