adplus-dvertising
frame-decoration

Question

Which of the following is correct way to convert a String to an int?
1.
String s = "123"; 
int i;
i = (int)s;

2.
String s = "123";
int i;
i = int.Parse(s);

3.
String s = "123"; 
int i;
i = Int32.Parse(s);

4.
String s = "123"; 
int i;
i = Convert.ToInt32(s);

5.
String s = "123"; 
int i;
i = CInt(s);

a.

1, 3, 5

b.

2, 4

c.

3, 5

d.

2, 3, 4

Posted under C# programming

Answer: (d).2, 3, 4

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Which of the following is correct way to convert a String to an int?

Similar Questions

Discover Related MCQs

Q. Which of the following statements about a String is correct?

Q. Which of the following statement is correct about a String in C#.NET?

Q. Which of the following is the correct way to find out the index of the second 's' in the string "She sells sea shells on the sea-shore"?

Q. Which statement is correct about following c#.NET code ?

int[] a= {11, 3, 5, 9, 6};

Q. What is the advantage of using 2D jagged array over 2D rectangular array?

Q. Which statement is correct about following set of code ?

int[, ]a={{5, 4, 3},{9, 2, 6}};

Q. Which is the correct way of defining and initializing an array of 3 integers?

Q. Choose selective differences between an array in c# and array in other programming languages.

Q. Which of the following string() method are used to compare two strings with each other?

Q. Choose the base class for string() method :

Q. Which of the following statement is correct about a string in C#.NET?

Q. Correct way to find if contents of two strings are equal ?

Q. Which of the following statements are correct ?

Q. Which of these operators can be used to concatenate two or more String objects?

Q. The Method use to remove white space from string?

Q. What is the String in C# meant for?

Q. What does the term ‘immutable’ means in term of string objects?

Q. To perform comparison operation on strings supported operations are :

Q. Correct way to convert a string to uppercase using string class method()?

Q. Which of these methods of class String is used to compare two String objects for their equality?