//The collection “fields” contain a set of rows with a column “FieldId”
DataRow[] fields = GetFields();
//This dictionary contains a set of key value pairs. keys represent FieldId’s and values represent OrderId’s
Dictionary<string, int> orders = new Dictionary<string, int>();
orders = LoadOrders();
I need to reorder the “fields” collection in the order of OrderId’s in the dictionary. The dictionary should be used as a cross reference to look up the FieldId and get the OrderId.
Sample data in fields:
Books
Movies
Electronics
Sample data in orders:
<Books, 2>
<Movies, 3>
<Electronics, 1>
The output by reordering the "fields" should be :
Electronics
Books
Movies
If anyone has any ideas on this, can you please share? Thank you.
This should work:
Or, if you prefer an in-place sort:
Of course you need to be sure that
ordersdictionary contains all the values present infieldscollection.