Commerce

Variables And Constants In C Sharp MCQs

Practice Variables And Constants In C Sharp MCQs for competitive exams.

Variables And Constants In C Sharp MCQs

Practice questions from this topic.

Which keyword is used to exit a loop prematurely in C#?

  1. A. continue
  2. B. skip
  3. C. exit
  4. D. break
Report Error

In C#, what is the result of the expression 3 / 2?

  1. A. 1
  2. B. 1.5
  3. C. 2
  4. D. 0
Report Error

What is the value of a variable in C# after it is declared but not assigned a value?

  1. A. Depends on the data type
  2. B. 0
  3. C. null
  4. D. undefined
Report Error

What is the purpose of declaring constants in C#?

  1. A. To store and manipulate data
  2. B. To declare variables
  3. C. To handle exceptions
  4. D. To define values that do not change
Report Error

Which of the following is a valid way to declare and initialize a string variable in C#?

  1. A. string = str
  2. B. str Hello
  3. C. string str = "Hello"
  4. D. str = "Hello"
Report Error

What is the scope of a global variable in C#?

  1. A. Limited to the block in which it is declared
  2. B. Throughout the program
  3. C. Limited to the file in which it is declared
  4. D. None of the above
Report Error

In C#, which keyword is used to declare a variable without specifying its data type explicitly?

  1. A. dynamic
  2. B. any
  3. C. var
  4. D. object
Report Error

Which of the following is NOT a valid constant name in C#?

  1. A. CONSTANT
  2. B. CONSTANT1
  3. C. _CONSTANT
  4. D. 1constant
Report Error

What is the default value of a boolean variable in C# if not initialized explicitly?

  1. A. FALSE
  2. B. TRUE
  3. C. 0
  4. D. Null
Report Error

What does the 'readonly' keyword do in C#?

  1. A. Makes a variable accessible outside its class
  2. B. Makes a variable constant
  3. C. Makes a variable read-only
  4. D. Makes a variable static
Report Error

Which keyword is used to define a constant in C#?

  1. A. static
  2. B. readonly
  3. C. final
  4. D. const
Report Error

What is the data type of the variable in C#?

  1. A. int
  2. B. string
  3. C. double
  4. D. char
Report Error