Showing posts with label .ToString. Show all posts
Showing posts with label .ToString. Show all posts

Tuesday, 20 December 2011

What will be the result of compiling and running the following code fragment?

Integer i= new Integer("10");

if (i.toString() == i.toString())

System.out.println("Equal");


else

System.out.println("Not Equal");


Choices:

A. Compiler error
B. Prints "Equal"
C. Prints "Not Equal"
D. None of the above


Correct choice:

  • C


Explanation:

Friday, 4 November 2011

What is the difference between Convert.ToString and .ToString() method ?

Just to give an understanding of what the above question means seethe below code.

int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));


We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what’s the difference.

The basic difference between them is “Convert” function handles