Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why does this block throw an error?
  2. public BallData GetBall(String Name)
  3.     {
  4.         //Check each item in the list for the name.
  5.         foreach (BallData Item in _BallList)
  6.         {
  7.             //If the name matches, return the item to the caller and exit the loop.
  8.             if (Item.Name == Name)
  9.             {
  10.                 return Item;
  11.             }
  12.             else
  13.             {
  14.                 // Otherwise, throw an exception to indicate that the ball wasn't found.
  15.                 throw new KeyNotFoundException("The ball name doesn't exist.");
  16.             }
  17.  
  18.  
  19.         }
  20.     }
  21.        
  22. foreach (BallData Item in _BallList)
  23.  {
  24.             //If the name matches, return the item to the caller and exit the loop.
  25.             if (Item.Name == Name)
  26.             {
  27.                 return Item;
  28.             }
  29.  
  30.   }
  31.   throw new KeyNotFoundException("The ball name doesn't exist.");