Govt. Exams
Entrance Exams
Auto-properties with get; set; syntax automatically create backing fields. Option C is an expression-bodied property (read-only).
The 'var' keyword declares a variable where the type is inferred at compile-time. Here, x is inferred as int, and GetType().Name returns 'Int32'.
Lambda expressions (introduced in C# 3.0) are a concise form of anonymous functions. They can infer return types and parameter types, and can access outer scope variables.
Generic methods use angle brackets <T> after the method name. The syntax is: public void Method<T>() where T is the type parameter.
For strings in C#, '==' is overloaded to compare values, and Equals() also compares values. However, for other reference types, '==' compares references while Equals() compares values.
HashSet<T> is an unordered collection that automatically prevents duplicate values. List<T> allows duplicates.
5 > 3 is true, but 10 < 8 is false. The && (AND) operator returns false because one condition is false.
The 'out' keyword is used when a method needs to return a value through a parameter. The parameter must be assigned before the method exits.
++x is pre-increment, so x becomes 6, then y is assigned 6. Both x and y are 6.
String interpolation uses the $ prefix followed by curly braces containing expressions.