This is a C# Program to generate register number automatically for 100 students using static constructor.
This C# Program Generates Register Number automatically for 100 Students using Static Constructor.
Here the static constructor is used to initialize static fields of a class with specific values.
Here is source code of the C# Program to Generate Register Number automatically for 100 Students using Static Constructor. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Generate Register Number automatically * for 100 Students using Static Constructor */ using System; using System.Collections.Generic; using System.Linq; using System.Text; 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(); } } }
This C# program is used to generate register number automatically for 100 students using static constructor. The static constructor is used to initialize static fields of a class with specific values. Print the generated numbers of the students.
#1 : 1001 #2 : 1002 #3 : 1003
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Check C# Books
- Check Computer Science Books
- Apply for Computer Science Internship
- Practice MCA MCQs
- Apply for C# Internship