WHY SHOULD WE OVERRIDE TOSTRING METHOD
1. What is ToString() Method.
2. Why should we override it ?
using System;
using System.Reflection;
namespace ConsoleApplication4
{
public class MainClass
{
public static void Main()
{
int Number = 10;
Console.WriteLine(Number.ToString());
Console.ReadLine();
Customer C1 = new Customer();
C1.FirstName = "Malla";
C1.LastName = "Gurram";
//Console.WriteLine(C1.ToString());
Console.WriteLine(Convert.ToString(C1));
Console.ReadLine();
}
}
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public override string ToString()
{
return this.LastName + ", " + this.FirstName;
}
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.