CommerceBasic Syntax And Data Types In C Sharp MCQs
Practice Basic Syntax And Data Types In C Sharp MCQs for competitive exams.
Basic Syntax And Data Types In C Sharp MCQs
Practice questions from this topic.
In C#, what is the result of the expression 5 / 2?
- A. 2.5
- B. 2
- C. Compilation error
- D. None of the above
Correct Answer: B
What is the purpose of the 'is' keyword in C#?
- A. Checks if two objects are equal
- B. Compares two values
- C. Checks if an object is compatible with a type
- D. Checks if an object is null
Correct Answer: C
What is the correct way to declare a multi-dimensional array in C#?
- A. numbers = int[]
- B. int[] numbers
- C. numbers[] int
- D. int[,] numbers
Correct Answer: D
Which data type is used to store true/false values in C#?
- A. bool
- B. boolean
- C. char
- D. int
Correct Answer: A
What is the purpose of the 'foreach' loop in C#?
- A. Performs a conditional iteration
- B. Terminates the loop
- C. Iterates over elements in a collection
- D. Executes a block of code repeatedly
Correct Answer: C
What is the default value of a reference type variable in C# if not explicitly initialized?
- A. 0
- B. FALSE
- C. TRUE
- D. Null
Correct Answer: D
What is the output of the following code: Console.WriteLine("10" + 5);
- A. Compilation error
- B. 10
- C. 105
- D. 15
Correct Answer: C
Which of the following is a valid way to declare a constant string in C#?
- A. MESSAGE const = "Hello"
- B. const string MESSAGE = "Hello"
- C. const MESSAGE = "Hello"
- D. None of the above
Correct Answer: B
What is the correct way to declare a floating-point variable with single precision in C#?
- A. Num float
- B. Var num
- C. float num
- D. double num
Correct Answer: C
What is the correct way to declare a constant in C#?
- A. constant MAX_VALUE = 100
- B. MAX_VALUE = 100
- C. int MAX_VALUE = 100
- D. const int MAX_VALUE = 100
Correct Answer: D
What is the default value of a boolean variable in C# if not explicitly initialized?
- A. 0
- B. Null
- C. FALSE
- D. TRUE
Correct Answer: C
What is the purpose of the 'static' keyword in C#?
- A. Initializes variables
- B. Declares constants
- C. Associates members with the class
- D. Defines methods
Correct Answer: C