MindFusion's Components
Home | Submit an interview question | Filter by category | Filter by job function | Filter by company
 
Member Information
User Id
Password
 
Forgot Password
Technology Category
.NET (1202)
Languages (103)
Database (146)
Operating System (48)
Reporting (5)
Third-Party Tools (2)
Testing (91)
OOP (75)
Web Development (40)
Design Patterns (89)
General (9)
Networking (88)
Hardware (63)
Brain Exercise (2)
Others (37)
 Our Network
.NET Heaven
C# Corner
Interview Corner
Longhorn Corner
Mindcracker
VB.NET Heaven
Home » .NET » .NET
What is the difference between Convert.toString and .toString() method ?
Posted by Purushottam Rathore Aug 12, 2009
Viewed : 810 times
Major Category : .NET
Minor Category : ASP.NET
Total Replies : 3
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
Puran Mehra
Aug 13, 2009

What is the difference between Convert.toString and. ToString() method ?

 

Convert.toString uses convert class method, which contains different static method to convert one primitive type to another primitive type.

 

While The ToString method of the Object class converts a type to a string type and it has many overloads.

Maruti Tathe
Aug 13, 2009
Hi,

This is very common interview question; been discussed many times. 
1) .toString() will not handle NULL; in case of NULL values it will raise NullReferenceException
2) Convert.toString() will handle NULL;



Purushottam Rathore
Aug 12, 2009

Just to give an understanding of what the above question means seethe below code.

int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));

We can convert the integer "i" using "i.ToString()" or "Convert.ToString" so what’s the difference.

The basic difference between them is "Convert" function handles NULLS while "i.ToString()" does not it will throw a NULL reference exception error. So as good coding practice using "convert" is always safe.

  
1
World Class ASP.NET Hosting - 3 Month Free Hosting, Click Here!
 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Advertise with us
Current Version: 2.2009.3.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved