Let us say we have a class by the name Employee.cs whith some properties and we want to override the ToString() method of Object class in the Employee class. The below program will do so.
using System;
public class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public string Gender { get; set; }
public string PhoneNumber { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public override string ToString()
{
string strEmployeeRecords = $"EmployeeId: {EmployeeId}";
strEmployeeRecords += $", EmployeeName: {EmployeeName}";
strEmployeeRecords += $", Gender: {Gender}";
strEmployeeRecords += $", PhoneNumber: {PhoneNumber}";
strEmployeeRecords += $", Email: {Email}";
strEmployeeRecords += $", Address: {Address}";
return String.Format(strEmployeeRecords);
}
}