Delegates Questions and Answers

Take Exam

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

1. Which of the following statements is incorrect about delegate?

  • Delegates are reference types.
  • Delegates are object oriented.
  • Delegates are type-safe.
  • Delegates serve the same purpose as function pointers in C and pointers to member function operators in C++.
Show Answer Report

2. In which of the following areas are delegates commonly used?     Remoting     Serialization     File Input/Output     Multithreading     Event handling

  • 1 and 2 only
  • 1 and 5 only
  • 1, 2 and 3 only
  • 4 and 5 only
Show Answer Report

3. Which of the following is the necessary condition for implementing delegates?

  • Class declaration
  • Inheritance
  • Run-time Polymorphism
  • Exceptions
Show Answer Report

4. Which of the following statements are correct about the delegate declaration given below?     delegate void del(int i);     On declaring the delegate a class called del will get created.     The signature of del need not be same as the signature of the method that we intend to call using it.     The del class will be derived from the MulticastDelegate class.     The method that can be called using del should not be a static method.     The del class will contain a one-argument constructor and an lnvoke() method.

  • 1, 2 and 3 only
  • 1, 3 and 5 only
  • 2 and 4 only
  • 4 only
Show Answer Report

5. Which of the following statements are correct about a delegate?     Inheritance is a prerequisite for using delegates.     Delegates are type-safe.     Delegates provide wrappers for function pointers.     The declaration of a delegate must match the signature of the method that we intend to call using it.     Functions called using delegates are always late-bound.

  • 1 and 2 only
  • 1, 2 and 3 only
  • 2, 3 and 4 only
  • All of the above
Show Answer Report

6. Which of the following statements are correct about delegates? Delegates are not type-safe.     Delegate is a user-defined type.     Only one method can be bound with one delegate object.     Delegates can be used to implement callback notification.     Delegates permit execution of a method on a secondary thread in an asynchronous manner.

  • 1 and 2 only
  • 1, 2 and 3 only
  • 2, 4 and 5 only
  • 4 and 5 only
Show Answer Report

7. Which of the following statements are correct about delegates?

  • Delegates cannot be used to call a static method of a class.
  • Delegates cannot be used to call procedures that receive variable number of arguments.
  • If signatures of two methods are same they can be called through the same delegate object.
  • Delegates cannot be used to call an instance function. Delegates cannot be used to call an instance subroutine.
Show Answer Report

8. Which of the following are the correct ways to declare a delegate for calling the function func() defined in the sample class given below? class Sample {     public int func(int i, Single j)     {         /* Add code here. */     } }

  • delegate d(int i, Single j);
  • delegate void d(int, Single);
  • delegate int d(int i, Single j);
  • delegate void (int i, Single j);
Show Answer Report

9. Suppose on pushing a button an object is to be notified, but it is not known until runtime which object should be notified. Which of the following programming constructs should be used to implement this idea?

  • Attribute
  • Delegate
  • Namespace
  • Interface
Show Answer Report

10. Which of the following statements is incorrect about a delegate?

  • A single delegate can invoke more than one method.
  • Delegates can be shared.
  • Delegate is a value type.
  • Delegates are type-safe wrappers for function pointers
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test