03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

708 ❘ APPENDIX A Solutions to Exercises<br />

This code creates four Task objects that execute the Fibonacci method (which returns<br />

a long result). The Fibonacci method receives as an argument the values Numbers[0],<br />

Numbers[1], Numbers[2], and Numbers[4]. (You could even make the Numbers array local to<br />

the event handler that creates the Tasks. Its only purpose in this program is to pass the values<br />

into the StartNew method.)<br />

Because the StartNew method passes the delegate an object as an argument, the<br />

Fibonacci method must be revised to take an object as a parameter. The following<br />

code shows the new method.<br />

private long Fibonacci(object data)<br />

{<br />

long N = (long)data;<br />

}<br />

if (N

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!