What is difference between Convert.ToString(variable) and
variable.ToString()




Answers were Sorted based on User's Feedback



What is difference between Convert.ToString(variable) and variable.ToString()..

Answer / hima sijo

convert.tostring handles Null value also where
Variable.tostring wont handle null value.It throw exception

Is This Answer Correct ?    8 Yes 0 No

What is difference between Convert.ToString(variable) and variable.ToString()..

Answer / abdul

Convert.ToString handles null where as simple
variable.ToString() doesn;t;

But Convert class is an optimization cost, when we use
inside any loop, need to minimize it

Sample ToString();

Will Work
int salary = 10000;
string oldSalary = salary.tostring();

Will Throw exeption
int salary = null;
string oldSalary = salary.tostring(); ---> throws exception

Sample Convert.ToString()
Will Work
int salary = 10000;
string oldSalary = Convert.ToString(salary);

Will Work
int salary = null;
string oldSalary = Convert.ToString(salary); null will return








Is This Answer Correct ?    13 Yes 7 No

What is difference between Convert.ToString(variable) and variable.ToString()..

Answer / sanjib ghosh

Dim salary As Int16
Dim oldSalary As String = salary.ToString()
Dim newSalary As String = Convert.ToString(salary)
MsgBox(oldSalary & "")
MsgBox(newSalary & "")
''No exception throw

both work same function

Is This Answer Correct ?    0 Yes 0 No




What is difference between Convert.ToString(variable) and variable.ToString()..

Answer / pavel

object ss =null;

string s1 = ss.ToString(); ---------- exeption
string s2 = Convert.ToString(ss); --- ""

--------------------
int ss =null; --- int can't be converted to null

--------------------
int ss = 1;

string s1 = ss.ToString(); ---------- "1"
string s2 = Convert.ToString(ss); --- "1"

Is This Answer Correct ?    0 Yes 2 No

Post New Answer



More C Sharp Interview Questions

What Are The .Net Object

2 Answers   Reliance, IMB,


What are the access allowed for compilation units(namespace),class and structs and what are its default access?

1 Answers   TCS,


How?s the DLL Hell problem solved in .NET?

3 Answers  


how can your software identify which version of dot net framework install in client pc and install framework accordingly

2 Answers   pspl,


What is Abstraction?

7 Answers   IBM, Google, HCL, MAHINDRA, Tech Mahindra,






boxing means converting value type to reference type and unboxing means converting reference type to value type.why we need boxing and unboxing?

3 Answers   Value Labs, General Mills,


An abstract class is inherited, an Interface also inherited(multiple inheritance), How it differences.

6 Answers   Synechron,


How can i load the text box and label at the runtime based on the existing text box and tabel

2 Answers   Patni, Merrill Lynch,


What if an error occurs in Catch block, how can you prevent it?

2 Answers   IBM,


can we declare a variable by name "this" in a class? Please explain?

3 Answers   IBM,


How we free the memory in C#.NET.

3 Answers   Synechron,


When Doveloped C#

2 Answers  






Categories