Performance Issue in Nested foreach Loop for Filtering Collection

  • Thread starter Thread starter ID GO
  • Start date Start date
I

ID GO

Guest
Performance Issue in Nested foreach Loop for Filtering Collection..

I tried 2 Ways...

1.


var routineArray = new ObservableCollection<IRoutine>();
IOrderedEnumerable<string> strNames = null;
var enumerable = getRoutines as IRoutine[] ?? getRoutines;
var routines = enumerable.ToList();


foreach (var st in strNames)
{
IRoutine first = null;
foreach (var x in routines)
{
if (x.Name == st)
{
first = x;
break;
}
}

routineArray.Add(first);
}



2.

foreach (var st in strNames)
routineArray.Add(routines.FirstOrDefault(x => x.Name == st));


Both are causing performance Issue while filtering and updating UI UWP.

Continue reading...
 
Back
Top