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's the basic difference between convert.ToString() and .ToString() in C#.net
Posted by kamal agrawal Aug 21, 2009
Viewed : 767 times
Major Category : .NET
Minor Category : ASP.NET
Total Replies : 4
Powerful ASP.NET Hosting w/ NO Setup Fees. Click Here!
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
kalit sikka
Aug 27, 2009

Lets understand the difference via this example

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.

http://kalitinterviewquestions.blogspot.com/

Suresh Ravi
Aug 25, 2009
Convert.ToString can handle null value. Object.ToString() will throw an error if the object is null. so its alway best to use Convert.Tostring() when you are converting reference type to string. Value type cannot be null so you can use .ToString() for value types.
Puran Mehra
Aug 25, 2009

.ToString() method lets you convert any value to a string.

W
hile convert.ToString() method uses the Convert class which provides shared methods that you can use to convert value with any data type to any other data type.

Purushottam Rathore
Aug 25, 2009
http://interviews.c-sharpcorner.com/Answer/Answers.aspx?QuestionId=2019&MajorCategoryId=1&MinorCategoryId=16
  
1

 

 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