V24s

"Get Updates : Subscribe to our e-mail newsletter to receive updates........" "Good Luck frnds" Admission 2019 Application Form 2019 Colleges Entrance Exam 2019 Results 2019 Notification 2019 University Educational Jobs 2019 Government Jobs 2019

Search This Blog v24s guys

15 April, 2013

C# - Difference between Convert.tostring and .tostring() method Example

Introduction:

In this article I will explain differences between .tostring() and Convert.tostring() in asp.net.

Description:

In previous post I explained difference between web application and website, difference between datareader, dataadapter and dataset, difference between tinyint,smallint,int,bigint and many articles relating to asp.net, SQL Server. Now I will explain differences between .tostring() and Convert.tostring() in asp.net.

The basic difference between them is “Convert.ToString(variable)” handles NULL values even if variable value become null but “variable.ToString()” will not handle NULL values it will throw a NULL reference exception error. So as a good coding practice using “convert” is always safe.

Example

//Returns a null reference exception for str.
string str;
object i = null;
str = i.ToString();

//Returns an empty string for str and does not throw an exception. If you dont
string str;
object i = null;
str = Convert.ToString(i);
I hope it helps.

No comments:

Popular Posts

Recent Posts

Google Analytics