1

Below is my class which holds data :

public class MyData
    {
        public string Region { get; set; }
        public int? RegionId { get; set; }
        public List<TestList> TestList { get; set; }
    }

 public class TestList
    {
        public int? TestId { get; set; }
        public List<Subvariants> SubvariantsList { get; set; }
    }

Now my List<MyData> contains data like this :

var RegionList = new List<MyData>();  // This data variable contains below list

[0] : RegionId = 101
      //other properties

[1] : RegionId = 45
      //other properties


[2] : RegionId = 67
      //other properties

[3] : RegionId = 51
      //other properties

Now I have 1 list contains contains RegionId like below :

var regionIdList  = new List<int>();
regionIdList = [67,101,51,45];

So I want to order my REgionList according to above order (regionIdList) so my final data in RegionList should be like this :

Expected Output in RegionList

[0] : RegionId = 67
      //other properties

[1] : RegionId = 101
      //other properties


[2] : RegionId = 51
      //other properties

[3] : RegionId = 45
      //other properties

So it is possible that I can get data with such custom ordering in my RegionList variable only? Because this variable some properties like TestList which in turn contains SubvariantsList and so after ordering I would like to preserve all those variables and list.

This is how I am trying but not getting how to do this :

RegionList = RegionList.OrderBy(o => o.RegionId) // this will sort data by regionid but not according to my custom order(regionIdList).
halfer
  • 19,824
  • 17
  • 99
  • 186
I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216

0 Answers0