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.

What is the correct way to declare a constant string in C#?

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

Which of the following is a valid variable declaration in C#?

  1. A. num = int
  2. B. int num
  3. C. int = num
  4. D. None of the above
Report Error

What is the data type of the following variable declaration: var x = 10;

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

In C#, how do you declare a variable without initializing it?

  1. A. num = int
  2. B. num int
  3. C. var num
  4. D. int num
Report Error

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

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

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

  1. A. MAX_VALUE
  2. B. my-constant
  3. C. 123constant
  4. D. _CONSTANT
Report Error

What is the correct way to declare a floating-point variable in C#?

  1. A. var num
  2. B. Num float
  3. C. double num
  4. D. float num
Report Error

What is the purpose of a variable in C#?

  1. A. To handle exceptions
  2. B. To define a method
  3. C. To store and manipulate data
  4. D. To define a constant
Report Error

In C#, which keyword is used to declare a variable that can hold values of any data type?

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

Which data type is used to store whole numbers in C#?

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

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

  1. A. Limited to the file in which it is declared
  2. B. Limited to the class in which it is declared
  3. C. Limited to the method in which it is declared
  4. D. Limited to the block in which it is declared
Report Error

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

  1. A. 1variable
  2. B. _variable
  3. C. variable1
  4. D. Variable
Report Error