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
What is difference between var dynamic and object in c#?
What is the property of class?
What is the difference between structure and class in c#?
What is tuple in c#?
We cannot create instances of static classes. Can we have constructors for static classes?
What is uint c#?
What is the main purpose of delegates in c#?
How to get the sum of last 3 items in a list using lambda expressions?
How do I format a string in c#?
When should I use static in C#?
Can we inherit sealed class in c#?
What is console writeline in c#?
How Global.asax is used ?
Do void methods have parameters?
What is executescalar in c#?