Below is the small source code which demonstrate how to override in built ToString() method in C# which is mostly used in exception handling.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace override_tostring_demo
{
class A
{
public override string ToString()
{
return "Hello";
//return base.ToString();
}
class M
{
static void Main(string[] args)
{
A a = new override_tostring_demo.A();
Console.WriteLine(a);
Console.ReadLine();
}
}
}
}
Comments
Post a Comment