*
Previous C# Question Answers-11 - 20 C# Question Answers-31 - 40 Next

C# (C-Sharp) Question Answers - 21-30

21. Explain "Mixed Syntax" in LINQ?

Mixed Syntax: We can use a mixture of both syntax by enclosing a query expression inside parentheses and make a call to method.

// Data 
List<int> numbers = new List<int>() { 11, 22, 33, 44, 55, 66, 77, 88, 99, 100 };
// Mixed syntax 
int query = (from num in numbers where num > 55 && num < 100 select num).Count();

// result: 4

22. Explain "Query Syntax (Expression Query)" in LINQ?

Query Syntax (Expression Query): It is like a SQL query syntax with just a few changes. The result of a query expression is a query object, which is usually a collection of type IEnumerable<T> or IQueryable<T>. This syntax is easy to read and write and at compile time, query expression is converted into Method Invocation.

// Data 
List<int> numbers = new List<int>() { 11, 22, 33, 44, 55, 66, 77, 88, 99, 100 }; 
// Query based syntax 
IEnumerable<int> query = from num in numbers where num > 55 && num < 100 select num; 

// result: 66,77,88,99

23. Explain 5 types of constructor in C#?

  • Default Constructor: Also called Empty Constructor, has no arguments.
  • Parameterized Constructor: Has arguments; object created by passing values.
  • Copy Constructor: Takes an object as parameter; copies values from one object to another.
  • Static Constructor: Initializes static fields of the class. Invoked once only when class is loaded.
  • Private Constructor: With private access modifier; prevents other classes from instantiating or deriving.

24. Explain an Assembly Qualified Name?

Assembly qualified name contains Assembly Name, Version, Token key and Culture information. Stored as metadata and defines scope.

25. Explain Generic Delegate?

Generic Delegate was introduced in .NET 3.5 and doesn’t require defining delegate instances manually.

  • Func
  • Action
  • Predicate

26. Explain IComparable and IComparer?

Both interfaces allow custom sorting:

  • IComparable: Allows sorting on only one property.
  • IComparer: Allows sorting on multiple properties.

27. Explain IDisposable Interface and Dispose() method?

Used to release unmanaged resources. Garbage collector releases managed memory automatically but cannot predict when. GC also doesn’t handle unmanaged resources like file handles or streams.

Dispose() performs tasks associated with freeing, releasing, or resetting unmanaged resources.

28. Explain IEquatable<T> and IEqualityComparer<T>?

  • IEqualityComparer<T>: Compares two objects of type T.
  • IEquatable<T>: Enables an object to compare itself to another.

29. Explain Interface and how it’s different from a Class.

An interface is a contract defining behavior without implementation. A class that implements an interface must provide the methods and properties defined in the interface.

  • Interface → describes behavior
  • Class → implements behavior
  • Multiple inheritance supported with interfaces, not with classes.

30. Explain Multicast Delegate?

A multicast delegate can invoke multiple methods. Use + to add methods and - to remove methods. Methods execute in sequence.

Back to Index
Previous C# Question Answers-11 - 20 C# Question Answers-31 - 40 Next
*
*