C# MCQ Question and Answer for Beginner



Which of the following is NOT a valid variable name in C#?
  • a) myVariable
  • b) number1
  • c) @data
  • d) 1stNumber (Invalid: cannot start with a number)

What does the Console.WriteLine() method do?

  • a) Reads input from the keyboard
  • b) Writes text to the console window (Correct)
  • c) Calculates the area of a circle
  • d) Generates a random number

What are the two main types of data in C#?

  • a) Text and numbers
  • b) Integers and strings (Correct)
  • c) Arrays and functions
  • d) Boolean and objects

What is the difference between a = and a == operator?

  • a) = assigns a value, == compares values (Correct)
  • b) = adds two numbers, == subtracts two numbers
  • c) Both are the same
  • d) = is for strings, == is for numbers

What is the syntax for an if statement?

  • a) if (condition) { code } (Correct)
  • b) while (condition) { code }
  • c) for (i = 0; i < 10; i++) { code }
  • d) switch (variable) { case 1: code1; case 2: code2; }

What does the break keyword do inside a loop?

  • a) Prints the loop counter
  • b) Exits the loop immediately (Correct)
  • c) Skips the current iteration of the loop
  • d) Doubles the value of the loop counter

What are the basic building blocks of a program?

  • a) Functions and variables (Correct)
  • b) Classes and objects
  • c) Loops and arrays
  • d) Comments and documentation

What is the output of 5 + 3 * 2?

  • a) 16
  • b) 10 (Correct: PEMDAS, multiplication before addition)
  • c) 5
  • d) Error

Which data type can store decimal numbers?

  • a) int
  • b) double (Correct)
  • c) string
  • d) bool

What is a comment used for?

  • a) To execute code (Not true)
  • b) To explain and document parts of your code (Correct)
  • c) To create variables
  • d) To print messages to the console

What is the correct way to declare an integer variable named age?

  • a) int age; (Correct)
  • b) String age;
  • c) Console.WriteLine(age);
  • d) age = 20;

What does the modulo operator % do?

  • a) Adds two numbers
  • b) Subtracts two numbers
  • c) Finds the remainder after division (Correct)
  • d) Multiplies two numbers

What is the difference between an array and a string?

  • a) An array holds multiple values, a string is a single character (Not true)
  • b) An array stores numbers, a string stores text (Not always true)
  • c) An array can have varying lengths, a string has a fixed length (Not true)
  • d) An array holds any data type, a string only holds characters (Correct)

What is the keyword used to create a function?

  • a) variable
  • b) loop
  • c) function (Not a C# keyword)
  • d) void (Used in function declaration)

How do you call a function in C#?

  • a) By writing its name inside main()
  • b) By writing its name followed by parenthesis (Correct)
  • c) By assigning it to a variable

 

C# MCQ Question and Answer for Beginner C# MCQ Question and Answer for Beginner Reviewed by Bhaumik Patel on 9:34 PM Rating: 5