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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi to all..I have to create an intranet application on C#.NET windows Application so please please let can you people help me as iam new in .NET and if u have any samples or website address from where i can get sample please let know.

3992


Explain the ways to deploy an assembly?

703


What are the types of delegates in c#?

634


In .NET which is the smallest unit of execution?

813


How do I make a dll in c#?

688


What is a interface in c#?

649


What are native functions?

641


How to Install uninstall assemblies into GAC?

672


Can you store strings in arrays?

737


What is the difference between Java and .NET garbage collectors?

712


How is a loop recorder monitored?

697


What is new method in c#?

683


What can be done with c#?

605


Are c and c# the same thing?

654


Which class does the remote object has to inherit?

809