← Zurück

ошибка при вызове MyTrades.Last(...)

Делаю так, все работает.

var direction = stringDirection == "Buy" ? OrderDirections.Buy : OrderDirections.Sell;

//проверим есть ли смысл улучшить позицию
if (MyTrades.Count() > 0)
{
   var lastInvertDirection = direction.Invert();
   var lastInvertTradeTime = MyTrades.Last(t => t.Order.Direction == lastInvertDirection).Order.Time;

   ...
}

А вот так выдаёт ошибку

var direction = stringDirection == "Buy" ? OrderDirections.Buy : OrderDirections.Sell;

//проверим есть ли смысл улучшить позицию
if (MyTrades.Count() > 0)
{
   var lastInvertDirection = MyTrades.Last().Order.Direction.Invert(); // direction.Invert();
   var lastInvertTradeTime = MyTrades.Last(t => t.Order.Direction == lastInvertDirection).Order.Time;

   ...
}

Ошибка такая: Исключение типа "System.InvalidOperationException" возникло в System.Core.dll, но не было обработано в коде пользователя

Дополнительные сведения: Последовательность не содержит соответствующий элемент

В чем может быть проблема?

War dieses Thema hilfreich?

Thema teilen

Kommentare (2)

Anmelden oder Konto erstellen, Melden Sie sich an oder registrieren Sie sich, um einen Kommentar zu hinterlassen

Alexander
Alexander

На msdn есть ответ

roof
roof
roof Autor

Alexander Mukhanchikov: На msdn есть ответ

Гуру чё!