Assign and print the roll number, phone number and address of two students having names "Sam" and "John" respectively by creating two objects of the class 'Student'. (For C sharp)
internal class Program
{
class Student
{
public int RollNumber { get; set; }
public string Name { get; set; }
public int Phone { get; set; }
public string Address { get; set; }
public Student(int rollNumber, string name,int phone,string address)
{
RollNumber = rollNumber;
Name = name;
Phone = phone;
Address = address;
}
public override string ToString()
{
return $"Roll Number: {RollNumber}; Name: {Name}; Phone: {Phone}; Address: {Address}";
}
}
static void Main(string[] args)
{
List<Student> students = new List<Student>()
{
new Student(0,"Sam",123456789,"SamAddress"),
new Student(1,"John",123456780,"JohnAddress")
};
foreach (Student student in students)
{
Console.WriteLine(student);
}
Console.ReadKey();
}
}
Comments
Leave a comment