C# (C Sharp) MCQs with answers Page - 23

Here, you will find a collection of MCQ questions on C# (C Sharp). Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
using System;

namespace MyApplication {
  class Program {
    static void Main(string[] args) {
      bool x = true;
      Console.Write(Convert.ToString(x));
    }
  }
}
  • (A) True
  • (B) true
  • (C) False
  • (D) false

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
using System;

namespace MyApplication {
  class Program {
    static void Main(string[] args) {
      double x = 10.25;
      Console.Write(Convert.ToInt32(x));
    }
  }
}
  • (A) 10.30
  • (B) 10.25
  • (C) 10
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code, if the input is 123?

Code:
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);
    }
  }
}
  • (A) Given number is:123
  • (B) Given number is: 123
  • (C) Given number is: "123"
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. Which is/are the correct method(s) to input a float value in C#?

  • (A) Parse(Console.ReadLine())
  • (B) ToSingle(Console.ReadLine())
  • (C) ToFloat(Console.ReadLine());
  • (D) Both A and B

A

Admin • 833.24K Points
Coach

Q. What is the difference between Console.Write() and Console.WriteLine() methods in C#?

  • (A) Write() writes a single character while Console.WriteLine() writes a complete line
  • (B) Write() writes the data on the console without printing a newline while Console.WriteLine() writes the data on the console along with printing a newline
  • (C) ToFloat(Console.ReadLine());
  • (D) Write() writes the string on the console while Console.WriteLine() writes the string as well as values of the variables on the console

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
using System;

namespace MyApplication {
  class Program {
    static void Main(string[] args) {
      int a = 10, b = 20;
      Console.WriteLine("{0},{0}", a, b);
    }
  }
}
  • (A) 10,10
  • (B) 10,20
  • (C) 20,20
  • (D) Error

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
using System;

namespace MyApplication {
  class Program {
    static void Main(string[] args) {
      int a = 10, b = 20;
      Console.WriteLine("{0}+{1}", a, b);
    }
  }
}
  • (A) 20
  • (B) 30
  • (C) 10+20
  • (D) 10+10

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
using System;

class Program {
  static void Main(string[] args) {
    int i = 2;
    int j = 10 / 4;

    if (i == j) {
      Console.WriteLine("True");
    } else {
      Console.WriteLine("False");
    }
  }
}
  • (A) True
  • (B) False
  • (C) Error
  • (D) None

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
using System;

class Program {
  static void Main(string[] args) {
    Console.WriteLine(true ^ true);
  }
}
  • (A) True
  • (B) False
  • (C) Error
  • (D) None

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
using System;

class Program {
  static void Main(string[] args) {
    int i = 100;

    do {
      Console.Write(i + " ");
      ++i;
    } while (i <= 50);
  }
}
  • (A) Error
  • (B) 100 101 102 ... Infinite
  • (C) 101
  • (D) 100

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ