Home Subjects C# Programming Basics & Syntax

C# Programming
Basics & Syntax

C# and .NET for campus placement

15 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 15
Topics in C# Programming
In C# 2024, which feature allows you to use pattern matching to deconstruct objects and filter simultaneously in a single expression?
A List patterns with logical operators
B Record types with positional parameters
C Nullable reference types
D Anonymous methods
Correct Answer:  A. List patterns with logical operators
EXPLANATION

C# 12 (2024) introduced advanced list patterns that allow filtering and deconstructing collections in pattern matching expressions, improving code readability and efficiency.

Test
What is the output of: string s = "Hello"; Console.WriteLine(s.GetHashCode() == s.GetHashCode());
A true
B false
C NullReferenceException
D Compiler Error
Correct Answer:  A. true
EXPLANATION

GetHashCode() on the same string returns the same hash code value, so comparison is true. Strings are immutable in C#.

Test
In C# 2024, what is the latest feature for null-safety introduced in recent versions?
A Nullable reference types
B required keyword for properties
C init-only properties
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

C# has progressively introduced nullable reference types, required keyword (C# 11), and init-only properties (C# 9) for better null-safety and immutability.

Test
What will be the output of: decimal price = 19.99m; Console.WriteLine(price.GetType().Name);
A "Decimal"
B "decimal"
C "Double"
D "Single"
Correct Answer:  A. "Decimal"
EXPLANATION

The GetType().Name returns the type name as "Decimal" (capitalized). The 'm' suffix specifies a decimal literal. The output shows the CLR type name, which is "Decimal".

Test
In C#, which keyword is used to implement multiple interface inheritance?
A extend
B inherit
C implements
D A class inherits by directly listing interfaces separated by commas
Correct Answer:  D. A class inherits by directly listing interfaces separated by commas
EXPLANATION

C# implements multiple interface inheritance by listing interfaces separated by commas after the class name: class MyClass : Interface1, Interface2. There is no 'extends' or 'implements' keyword in C#.

Test
What is the output of: int x = 10; int y = x++; Console.WriteLine(x + ", " + y);
A 10, 10
B 11, 10
C 11, 11
D 10, 11
Correct Answer:  B. 11, 10
EXPLANATION

Post-increment (x++) returns the current value before incrementing. So y = 10, then x becomes 11. Output is '11, 10'.

Test
Which of the following correctly demonstrates method overloading in C#?
A Two methods with same name but different return types
B Two methods with same name but different parameter types or count
C Two methods with different names but same parameters
D Two methods with same signature but different access modifiers
Correct Answer:  B. Two methods with same name but different parameter types or count
EXPLANATION

Method overloading requires same method name but different parameter types, count, or order. Return type alone is insufficient for overloading.

Test
What will be the result of: string text = null; Console.WriteLine(text ?? "Default");
A null
B Default
C NullReferenceException
D Empty string
Correct Answer:  B. Default
EXPLANATION

The null-coalescing operator (??) returns the right operand if the left is null. Since text is null, it prints 'Default'.

Test
In C#, what is the primary purpose of the 'using' statement?
A To import namespaces
B To ensure proper resource disposal and implement IDisposable
C To declare variables
D To create aliases for types
Correct Answer:  B. To ensure proper resource disposal and implement IDisposable
EXPLANATION

The 'using' statement ensures that Dispose() is called on objects implementing IDisposable, preventing resource leaks. Importing namespaces is a different use of 'using'.

Test
Q.10 Hard Basics & Syntax
Which of the following correctly describes method overloading in C#?
A Methods must have the same name and same parameter list
B Methods can have the same name with different parameter types, count, or order
C Only the return type can differ between overloaded methods
D Method overloading is not supported in C#
Correct Answer:  B. Methods can have the same name with different parameter types, count, or order
EXPLANATION

Method overloading allows same method name with different signatures (parameter types, count, or order). Return type alone cannot differentiate overloaded methods.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips