Sample difference between ToString() and Convert.ToString() through console application
using System;
namespace ConsoleApplicationSample
{
class Convert_Tostring
{
public static void Main()
{
#region x.toString()
string s = "";
object o = null;
s = o.ToString();
Console.Write(s.ToString());
Console.ReadLine();
//returns a
null reference exception for s.
#endregion
#region Convert.toString()
string s;
object o =
null;
s =
Convert.ToString(o);
Console.Write(Convert.ToString(s));
Console.ReadLine();
//returns an
empty string for s and does not throw an exception.
#endregion
}
}
}
https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos
0 comments
Post a Comment