0

I have a list of type 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;
    }
}

I'm trying to remove all the elements that have price equal to NaN. This is what I have but for some reason it won't work.

BidStack.RemoveAll(item => item.Price == Double.NaN);
AskStack.RemoveAll(item => item.Price == Double.NaN);

Any suggestions?

SOLVED:

BidStack.RemoveAll(item => Double.IsNaN(item.Price));
AskStack.RemoveAll(item => Double.IsNaN(item.Price));
kknaguib
  • 749
  • 4
  • 12
  • 33

1 Answers1

8

The == operator does not work as you expect on NaN, instead use Double.IsNaN(x).

Dai
  • 141,631
  • 28
  • 261
  • 374