我有一个StackBuilder类型列表:
public class StackBuilder
{
private int quoteID = 0;
private double price = 0;
private double size = 0;
public int QuoteID
{
get { return quoteID; }
}
public double Price
{
get { return price; }
}
public double Size
{
get { return size; }
}
public StackBuilder(int quoteID, double price, double size)
{
this.quoteID = quoteID;
this.price = price;
this.size = size;
}
}
我正在尝试删除所有价格等于NaN的元素。这就是我所拥有的,但由于某种原因它不会起作用。
BidStack.RemoveAll(item => item.Price == Double.NaN);
AskStack.RemoveAll(item => item.Price == Double.NaN);
有什么建议吗?
解决:
BidStack.RemoveAll(item => Double.IsNaN(item.Price));
AskStack.RemoveAll(item => Double.IsNaN(item.Price));
答案 0 :(得分:7)
==
运算符无法按预期在NaN
上运行,而是使用Double.IsNaN(x)
。