C# Lambda Expression Speed

Posted by Nathan on Stack Overflow See other posts from Stack Overflow or by Nathan
Published on 2010-03-09T02:04:37Z Indexed on 2010/03/09 2:06 UTC
Read the original article Hit count: 391

Filed under:
|

I have not used many lambda expressions before and I ran into a case where I thought I could make slick use of one. I have a custom list of ~19,000 records and I need to find out if a record exists or not in the list so instead of writing a bunch of loops or using linq to go through the list I decided to try this:

 for (int i = MinX; i <= MaxX; ++i)
        {
            tempY = MinY;

            while (tempY <= MaxY)
            {
                bool exists = myList.Exists(item => item.XCoord == i && item.YCoord == tempY);

               ++tempY;
            }
        }

Only problem is it take ~9 - 11 seconds to execute. Am I doing something wrong is this just a case of where I shouldn't be using an expression like this?

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about lambda-expressions