2b. (iii). Constructor overloading

Program:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Practical2.b3

{
struct  Student

{
public int roll_number;

public string name;

public Student(int x, string s)
 {
roll_number = x;

name = s;
}
          public Student(string s, int x)

{
roll_number = x;
name = s;
}

public void printValue()
{

Console.WriteLine("Roll Number: " + roll_number);
Console.WriteLine("Name: " + name);

}

}

class Program
{

static void Main(string[] args)

{
Student S1 = new Student(001,"ABCD"); 
Student S2 = new Student("WXYZ",102);

S1.printValue();
S2.printValue();

Console.ReadKey(); 
}
} 
}

Comments