I have a list containing some objects and an string array. I would like to optimize this code if possible. Currently, the Big O notation is O(n^2)
The simplified version of the code:
List<Client> clients = new List<Client>();
// ... fill the 'clients' list
string[] ids = File.ReadAllLines("ids.txt");
List<Client> result = new List<Client>();
for (int i = 0; i < ids.Length; i++)
{
foreach (var item in clients)
{
if (clients.Id == ids[i])
{
result.Add(item);
break;
}
}
}
return result;