Monday 6 February 2017

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; }
      
      
    }
}

   

No comments:

Post a Comment

Note: only a member of this blog may post a comment.