C# Lambda Expression Speed
- by Nathan
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.