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.

168 ❘ CHAPTER 7 Program Control Statements<br />

11. The following code sets an overdue Bill object’s Penalty property to $5 or 10 percent of<br />

the outstanding balance, whichever is greater.<br />

bill.Penalty = bill.Status == BillStatus.Overdue <br />

bill.Balance < 50m 5m : bill.Balance * 0.1m : 0m;<br />

Rewrite this code so that it doesn’t use the : operator.<br />

12. Rewrite the following code so that it doesn’t use the operator.<br />

Student student = GetStudent("Steward Dent") new Student("Steward Dent");<br />

13. Write a for loop that displays the multiples of 3 between 0 and 100 in largest-tosmallest<br />

order.<br />

14. What values does the following loop display<br />

for (int i = 1; i < 100; i += i) Console.WriteLine(i);<br />

15. Write a program that displays the dates that are Friday the 13ths starting at the beginning<br />

of the current year. Display dates one year at a time as long as the user clicks Yes in a dialog<br />

asking if the program should continue for the next year.<br />

16. Rewrite the following foreach loop so that it doesn’t use the continue statement.<br />

foreach (Employee employee in employees)<br />

{<br />

if (employee.IsExempt) continue;<br />

}<br />

// Process the employee.<br />

...<br />

What advantage does the continue statement have over your solution When would it be<br />

even more useful<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!