1. What is the default value of an int in C#?
Answer:
Explanation:
In C#, the default value of an int (integer) type is 0.
2. Which of the following is a valid declaration of a variable in C#?
Answer:
Explanation:
In C#, variable names cannot start with a number, be a keyword, or match the name of built-in data types.
3. How do you declare a constant variable in C#?
Answer:
Explanation:
In C#, a constant variable is declared using the 'const' keyword followed by the data type and the variable name.
4. What is the correct way to declare a nullable integer in C#?
Answer:
Explanation:
In C#, a nullable integer is declared using the int? syntax.
5. Which of the following data types has the largest storage capacity in C#?
Answer:
Explanation:
In C#, the long data type has a larger storage capacity compared to int, short, and byte.
6. What does the following declaration represent in C#? string[] names;
Answer:
Explanation:
In C#, string[] is the syntax used for declaring an array of strings.
7. Which keyword is used to declare a variable that can be modified by different threads safely in C#?
Answer:
Explanation:
The 'volatile' keyword in C# is used to indicate that a field might be modified by multiple threads.
8. In C#, which of the following is the correct way to declare a variable for floating point numbers with high precision?
Answer:
Explanation:
In C#, the 'decimal' type is used for high-precision floating point numbers. The 'm' suffix is used for decimal literals.
9. What is the output of the following C# code?
int x = 10;
int y = x++;
Answer:
Explanation:
The post-increment operator (x++) increments x after its current value is assigned to y. So, y gets 10 and x becomes 11.
10. Which of the following is true about the 'var' keyword in C#?
Answer:
Explanation:
The 'var' keyword in C# enables implicit type declaration, allowing the compiler to infer the type of the variable at compile time.
11. In C#, which data type is used to store a single character?
Answer:
Explanation:
The 'Char' data type in C# is used to store a single Unicode character.
12. What is the range of values for a ushort data type in C#?
Answer:
Explanation:
The 'ushort' (unsigned short) data type in C# has a range of 0 to 65,535.
13. Which of the following correctly declares a multi-dimensional array in C#?
Answer:
Explanation:
In C#, a multi-dimensional array is declared using the syntax 'int[,]'.
14. What is the default value of a boolean variable in C#?
Answer:
Explanation:
The default value of a boolean variable in C# is 'false'.
15. In C#, what is the output of Console.WriteLine(5 / 2);?
Answer:
Explanation:
In C#, the division of two integers results in an integer. 5 / 2 yields 2 since the fractional part is discarded.
16. How do you explicitly convert a float to an int in C#?
Answer:
Explanation:
Explicit casting is done using the (int) syntax in C#.
17. What is the purpose of the 'dynamic' keyword in C#?
Answer:
Explanation:
The 'dynamic' keyword in C# is used for variables that are dynamically typed, allowing their type to be determined at runtime.
18. Which of the following is a valid way to declare a string in C#?
Answer:
Explanation:
In C#, both 'string' (alias) and 'String' (class name in the System namespace) are valid for string declarations.
19. What does the 'readonly' keyword do in C#?
Answer:
Explanation:
The 'readonly' keyword in C# indicates that assignment to the field can only occur as part of the declaration or in a constructor in the same class.
20. What is the maximum value of a 'byte' data type in C#?
Answer:
Explanation:
In C#, the 'byte' data type is an 8-bit unsigned integer with a range from 0 to 255.