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);
    }
  }
}
  1. Given number is:123
  2. Given number is: 123
  3. Given number is: "123"
  4. 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'

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.