IT1811 Delegates and Events Delegates (Harwani, 2015)
18 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the main purpose of a delegate in C#?

  • To create new classes
  • To store multiple methods in a single container (correct)
  • To encapsulate data
  • To handle exceptions
  • How is a delegate declared in C#?

  • Use the 'class' keyword
  • Use the 'delegate' keyword (correct)
  • Use the 'method' keyword
  • Use the 'function' keyword
  • What comes after the delegate keyword when declaring a delegate in C#?

  • Class name
  • List of parameters
  • Access modifier
  • Return type (correct)
  • How do you instantiate a delegate in C#?

    <p>Using the 'new' keyword</p> Signup and view all the answers

    What does a delegate allow you to do in C#?

    <p>Call any method as long as its signature matches</p> Signup and view all the answers

    When invoking a referenced method with a return type, what should be considered regarding the delegate's parameters?

    <p>The parameters should match exactly with those of the referenced method</p> Signup and view all the answers

    In C#, after declaring an event, how do you add a delegate to the event?

    <p>Use the += operator</p> Signup and view all the answers

    What does the add accessor do in C# event accessors?

    <p>Registers a new subscription to an event</p> Signup and view all the answers

    What automatically generates two event accessors after adding an event to a class in C#?

    <p>Compiler</p> Signup and view all the answers

    Which operator is used to remove a delegate from an event in C#?

    <p>-=</p> Signup and view all the answers

    What is the purpose of the add and remove accessors in C# event accessors?

    <p>Register and unregister subscriptions</p> Signup and view all the answers

    When declaring an event in C#, what keyword is followed by the name of the delegate?

    <p>Event</p> Signup and view all the answers

    What is a key similarity between generic delegates and other data types like string, int, or decimal?

    <p>They all can point to various data types</p> Signup and view all the answers

    What is a distinctive feature of delegates compared to interfaces?

    <p>Delegates can implement a method only once</p> Signup and view all the answers

    Which is a correct statement about interfaces in C#?

    <p>An interface can reference any method of a class that provides arguments and return types</p> Signup and view all the answers

    Why are delegates considered 'safe callbacks'?

    <p>They have no implementation and are just callbacks</p> Signup and view all the answers

    What is a notable difference between delegates and interfaces?

    <p>Delegates allow referencing any method of a class with specific arguments and return type</p> Signup and view all the answers

    Which statement is true regarding delegates and interfaces in C#?

    <p>Interfaces allow extending some objects' functionality</p> Signup and view all the answers

    More Like This

    C# Delegates in .NET
    15 questions

    C# Delegates in .NET

    HottestPerception498 avatar
    HottestPerception498
    IT1811 Delegates and Events
    32 questions

    IT1811 Delegates and Events

    EndorsedSavannah3038 avatar
    EndorsedSavannah3038
    IT1811 Delegates and Events Quiz
    7 questions
    IT1811: Delegates and Events
    9 questions
    Use Quizgecko on...
    Browser
    Browser