Home »
MCQs »
C# MCQs
What will be the output of the following C# code, if the input is 123? | Question 3
32. What will be the output of the following C# code, if the input is 123?
using System;
namespace MyApplication {
class Program {
static void Main(string[] args) {
Console.WriteLine("Enter a number:");
int num = Console.ReadLine();
Console.WriteLine("Given number is: " + num);
}
}
}
- Given number is:123
- Given number is: 123
- Given number is: "123"
- Error
Answer: D) Error
Explanation:
In C#, Console.ReadLine() is used to read the string and here we are trying to input an integer value. Thus, the output will be an error.
Cannot implicitly convert type `string' to `int'