What will be the output of the following C# code?
static void Main(string[] args)
{
Console.WriteLine("This is a Console Application:");
Console.Write("Please enter your lucky number:");
string val1 = Console.ReadLine();
int val2 = System.Convert.ToInt32(val1, 10);
val2 = val2 * val2;
Console.WriteLine("square of number is:" +val2);
Console.Read();
}
static void Main(string[] args)
{
Console.WriteLine("This is a Console Application:");
Console.Write("Please enter your lucky number:");
string val1 = Console.ReadLine();
int val2 = System.Convert.ToInt32(val1, 10);
val2 = val2 * val2;
Console.WriteLine("square of number is:" +val2);
Console.Read();
}
A. Compile time error
B. Runs successfully does not print anything
C. Runs successfully, ask for input and hence displays the result
D. Syntax Error
Answer: Option C
Join The Discussion