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 is a struct in C#?

0 Answers   Arigo Infotech,


Can private virtual methods be overridden in c#.net?

0 Answers  


Explain About Postback

0 Answers   BirlaSoft,


Can a struct have a default constructor (a constructor without parameters) or a destructor in c#?

0 Answers  


What framework is used for performance testing/load testing?

0 Answers   TCS,






How is the syntax written to inherit from a class in C#?Give an example ?

0 Answers   Siebel,


What are the two kinds of properties?

10 Answers   Wipro,


what is the difference between convert.tostring() and tostring() functions ?

0 Answers   QuestPond,


How garbage collection deals with circular references.

0 Answers  


code for arranging given number in possible permutation ways ex:123,321,312,132,231,213.

0 Answers  


in object oriented programming, how would you describe encapsulation?

0 Answers   Siebel Systems,


give suitable code for all login controls

1 Answers  






Categories