What is difference between Convert.ToString(variable) and
variable.ToString()
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
Write a program in c# to find the angle between the hours and minutes in a clock?
what optimizations does the c# compiler perform when you use the /optimize+ compiler option?
Is c# difficult to learn?
What are bitwise logical operators?
what is default accessibility for a class? what is difference b/w viewstate and controlstate? what is the default access specifier for a top level class which are not nested into other classes?
what are the differences b/w structure and class?
Can we create instance of private class in c#?
How do you type a null character?
How does c# achieve polymorphism?
What is winforms c#?
What?s an abstract class?
Is functional interface runnable?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)