Respuesta :
Answer:
Following are the program in c#
using System;// namespace
public class student1 // main class
{
public static void Main(string[] args) // main method
{
Student sam = new Student("45", "san", "tan");
Student ram = new Student("104", "ran", "pan");
Console.WriteLine(sam); // print the data of first object
Console.WriteLine(ram);// print the data of second object
}
}
public class Student // student class
{
public string ID ;// properties id
public string FirstName; //properties name
public string LastName; //properties LastName;
public Student(string id, string firstName, string lastName) // parametrized constructor
{
ID = id;
FirstName = firstName;
LastName = lastName;
}
public override string ToString() // overriding the method ToString
{
return "ID: " + ID + ", FirstName: " + FirstName + " LastName:" + LastName;
}
}
Explanation:
In this program we create a class student and declared a three variable i.e ID, FirstName, and LastName .We initialize them into into constructor and create a override method ToString() which return the string .In the main method method we create a two object of student class and display them using writeline method .
Output:
ID:45, FirstName:san lastName:tan
ID:104, FirstName:ran lastName:pan