this Keyword4 Master Constructor Implementation C# with Example



this Keyword4 Master Constructor Implementation C# with Example

 	using System;

	namespace CSharpClass
	{
		class Student
		{ 
			int rollNumber;
			string name;
			
			public Student() {}
			public Student(int rn) : this(rn, "") {}			
			public Student(string name) : this(0, name) {}
			
			public Student(int rn, string name) 
			{
				this.name = name;
				rollNumber = rn;
			}

			public void Display()
			{
				Console.WriteLine("Roll Number: " + rollNumber);
				Console.WriteLine("Name: " + name);
			}
		}
				
		class UsingStudent
		{
			static void Main( )
			{
				Console.WriteLine("First Student Information: ");
				Student stdObj1 = new Student();
				stdObj1.Display();
				
				Console.WriteLine("\nSecond Student Information: ");
				Student stdObj2 = new Student(100);
				stdObj2.Display();
				
				Console.WriteLine("\nThird Student Information: ");
				Student stdObj3 = new Student("Kuldeep Mishra");
				stdObj3.Display();
			
				Console.WriteLine("\nFourth Student Information: ");
				Student stdObj4 = new Student(200, "Kuldeep Mishra");
				stdObj4.Display();
			}
		}
	}
 

0 Comment's

Comment Form