Step 1:- Explanation
1. .ToString () doesn't handle the null value.
2. Convert.ToString()
handles null value.
Step 2:- .ToString()
using System;
namespace ToString
{
public class Program
{
static void Main(string[]
args)
{
Object obj
= null;
string value1
= obj.ToString(); //Error
Console.WriteLine(value1);
Console.ReadLine();
}
}
}
Step
3:- Output
Step 4:- Convert.ToString()
using System;
namespace ConvertDotToString
{
public class Program
{
static void Main(string[]
args)
{
Object obj
= null;
string value1
= Convert.ToString(obj); //Return
Null Or Blank
Console.WriteLine(value1);
Console.ReadLine();
}
}
}
Step 5:- Output