nerdexam
Microsoft

98-372 · Question #80

You are creating an application using .NET Framework 4.0. You write the following delegate: public delegate void AlertEventHandler(object sender, AlertEventArgs e); Based on the above delegate, which

The correct answer is D. public void AlertStart(object sender, AlertEventArgs e). The following declaration can respond to an event: public void AlertStart(object sender, AlertEventArgs e) Event handlers must match the signature of the delegate. In this case, the delegate needs two parameters, i.e., Object and AlertEventArgs, and returns void. The delegate dec

Understanding Methods and Events

Question

You are creating an application using .NET Framework 4.0. You write the following delegate:

public delegate void AlertEventHandler(object sender, AlertEventArgs e); Based on the above delegate, which of the following declarations can respond to an event?

Options

  • Apublic void AlertStart()
  • Bpublic void AlertStart(object sender, EventArgs e)
  • Cpublic EventArgs AlertStart(object sender, AlertEventArgs e)
  • Dpublic void AlertStart(object sender, AlertEventArgs e)

How the community answered

(49 responses)
  • A
    12% (6)
  • B
    10% (5)
  • C
    4% (2)
  • D
    73% (36)

Explanation

The following declaration can respond to an event: public void AlertStart(object sender, AlertEventArgs e) Event handlers must match the signature of the delegate. In this case, the delegate needs two parameters, i.e., Object and AlertEventArgs, and returns void. The delegate declaration takes the following form: [attributes] [modifiers] delegate result-type identifier ([formal-parameters]); where, attributes is optional for additional declarative information modifiers is optional and the allowed modifiers are new and the four access modifiers result-type matches the return type of the method identifier is the delegate name formal-parameters is an optional parameter list

Topics

#delegate signatures#event handlers#method signatures#EventArgs

Community Discussion

No community discussion yet for this question.

Full 98-372 Practice