I am trying to sort a custom list based on a string array, but I am failing miserably e.g. its not sorting the list at all,
Public class CrateOrder
{
public int Id { get; set; }
public string Name { get; set; }
public Stream OrderStream { get; set; }
}
string[] selectedFruits = {"Apple", "Mango"}; // in real get from web services
var selectedFruitsList = selectedFruits.ToList();
List<CrateOrder> cFruit = GetCrateOrderFromWebServices();
var sorted = cFruit.OrderBy(s => selectedFruitsList.IndexOf(s.Name)).ToList();
It's not sorting the list properly, I want CrateOrder list item to be ordered based on selectedFruits...
cFruitwith yourselectedFruits. An input and expected output forcFruitwould help.IndexOfwill do a case-sensitive search by default, unless specifying a different rule.