Delegates Questions and Answers
Delegates in C# are powerful constructs that allow methods to be passed as parameters, forming the foundation for event handling and lambda expressions. This section contains C# programming questions and answers focusing on delegate declaration, invocation, and multicast behavior. These C# delegates questions with answers are commonly asked in Infosys, TCS, and Capgemini technical interviews. Understanding delegates enhances your grasp of advanced C# features like events and asynchronous programming, which are key to writing flexible, maintainable applications.
Delegates
Showing 10 of
32 questions
21. What does the Action delegate represent?
- A method that returns a value
- A method that does not return a value
- A method that takes no parameters
- A method that handles exceptions
22. What does the Func delegate represent?
- A method that returns a value
- A method that does not return a value
- A method that takes no parameters
- A method that handles events
23. What is the Predicate delegate used for?
- A method that returns a string
- A method that takes one input and returns boolean
- A method that sorts collections
- A method that handles user input
24. How do you remove a method from a multicast delegate?
- Using the Remove() method
- Using the - operator
- Using the Delete() method
- Using the / operator
25. What are anonymous methods in C#?
- Methods with unique names
- Inline methods without a name
- Static methods only
- Methods that cannot be called directly
26. What are lambda expressions in C#?
- A way to create named methods
- Concise way to write anonymous methods
- A type of loop expression
- A database query syntax
28. What is the main advantage of using events over plain delegates?
- They are faster than delegates
- They use less memory
- They provide encapsulation and prevent direct invocation
- They automatically handle exceptions
29. Can delegates be used for asynchronous programming?
- No, delegates are only for synchronous calls
- Yes, using BeginInvoke and EndInvoke
- Only in .NET Framework 4.0 and above
- Only for static methods
30. What is covariance in delegates?
- Returning more derived types
- Accepting more derived parameters
- Handling multiple return types
- Working with generic types only