[Solved] can I sort a list based on another list in C# [closed]


Create a class that contains both items, and then sort that list:

class Item
{
    public int Id {get;set}
    public string Text {get;set;}
}

var unsorted = new List<Item>
{
    new Item{Id = 3, Text = "eg3"},
    new Item{Id = 1, Text = "eg1"},
    new Item{Id = 2, Text = "eg2"},
}

var sorted = unsorted.OrderBy(x=>x.Id);

Further examples of OrderBy here: https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.orderby

1

solved can I sort a list based on another list in C# [closed]