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

How to Show Message box in Metro Style App?

558


What is autopostback in c#?

467


What is a Jagged Array in C#?

540


How many variables do you need?

488


What is the difference between array and arraylist in c#?

476






What is callback delegate in c#?

449


Is there hashmap in c#?

454


What is Fragmentation and its Types?

555


What is ildasm and obfuscator in net?

534


Does a class need a constructor c#?

481


What is the difference between integer and double?

459


Define MSIL, and how does it works? Why our developers need an appreciation of it if at all?

498


Are c# constructors the same as c++ constructors?

510


How many types of inheritance are there in c#?

469


What happens during the process of boxing?

591