«Не все пути кода возвращают значение»Почему этот блок выдает ошибку?
public BallData GetBall(String Name)
{
//Check each item in the list for the name.
foreach (BallData Item in _BallList)
{
//If the name matches, return the item to the caller and exit the loop.
if (Item.Name == Name)
{
return Item;
}
else
{
// Otherwise, throw an exception to indicate that the ball wasn't found.
throw new KeyNotFoundException("The ball name doesn't exist.");
}
}
}
Вы понимаете, это будет смотреть только на первый элемент в '_BallList' перед возвратом/метанием? –