Menu Close

DIFFERENCE BETWEEN CONVERT.TOSTRING() AND TOSTRING()

DIFFERENCE BETWEEN CONVERT.TOSTRING() AND TOSTRING()

Convert.Tostring() handles null, while ToString() doesn’t  and throws a NULL
Reference exception.

Depending on the type of the application architecture and what you are trying to achieve , 
you choose one over the other.

using System;
namespace ConsoleApplication4
{
    public class MainClass
    {
        public static void Main()
        {
            Customer C1 = null;
            string str = Convert.ToString(C1);
            Console.WriteLine(str);
            Console.ReadLine();
        }
    }
    public class Customer
    {
        public string Name { get; set; }
      
      
    }
}
   

Share this:
Posted in Blog

Related Posts