Exercises


  1. "Using Trace.WriteLine() is preferable to using Debug.WriteLine() as the Debug version only works in debug builds." Do you agree with this statement? Why?

  2. Provide code for a simple application containing a loop that generates an error after 5000 cycles. Use a breakpoint to enter Break mode just before the error is caused on the 5000th cycle (note: a simple way to generate an error is to attempt to access a nonexistent array element, such as myArray[1000] in an array with a hundred elements).

  3. "finally code blocks only execute if a catch block isn't executed." True or false?

  4. Given the enumeration data type orientation defined below, write an application that uses Structured Exception Handling (SEH) to cast a byte type variable into an orientation type variable in a safe way. Note that you can force exceptions to be thrown using the checked keyword, an example of which is shown below. This code should be used in your application:

     enum orientation : byte { north = 1, south = 2, east = 3, west = 4 } myDirection = checked((orientation)myByte); 




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net