CSE 445 MIDTERM 2 EXAM QUESTIONS AND UPDATED CORRECT ANSWERS 2024/2025
What is a delegate?
A delegate is a reference type that can be used to reference a method. It encapsulates the method.
How is delegate declared?
public delegate void MyDelegate();
Give delegate code to reference:
public st...
cse 445 midterm 2 exam questions and updated corre
Written for
CSE 445
All documents for this subject (44)
Seller
Follow
NurseAdvocate
Reviews received
Content preview
CSE 445 MIDTERM 2 EXAM QUESTIONS AND UPDATED
CORRECT ANSWERS 2024/2025
What is a delegate?
A delegate is a reference type that can be used to reference a method. It encapsulates
the method.
How is delegate declared?
public delegate void MyDelegate();
Give delegate code to reference:
public static int Number(int x)
{
return x;
}
public delegate int NumDel(int x);
NumDel d1 = new NumDel(Number);
d1(2);
Give delegate code that would call all three methods when the delegate is
invoked:
public static void method1(){}, public static void method2(){}, public void
method3(){}
public delegate void MethodDel();
, MethodDel d = new MethodDel(method1);
d += new MethodDel(method2);
Class m3 = new Class();
d+= new MethodDel(m3.method3);
d();
The method that a delegate references or encapsulates has to have the same
what?
The method and delegate must have the same signature/prototype
After a delegate is declared, how do we use it?
Like a class, create an instance of the delegate with static or instance method passed
as parameter.
Delegates are similar to what in c++?
Delegates are similar to a function pointer in c++
Describe how a delegate can be used to define callback methods?
A delegate can be used to define callback methods my passing the name of the event
handler to the delegate reference
Give basic code of how to combine a delegate and an event.
1. Declare delegate:
public delegate void MyDelegate();
2. Declare event:
public static event MyDelegate Myevent;
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller NurseAdvocate. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for £8.16. You're not tied to anything after your purchase.