Lexicographically sorted list of lists of strings

前端 未结 4 1572
轻奢々
轻奢々 2021-01-19 05:39

Currently, I am trying to implement a code to generate frequent sequences. In doing so I need to get an in-place sort of a list of lists of strings as follows:



        
4条回答
  •  鱼传尺愫
    2021-01-19 06:30

    You can try below code:

            List input1 = new List() { "a", "b", "d" };
            List input2 = new List() { "a", "b", "c" };
    
            //Instead of adding input as List, add it as string
            string delimiter = ",";
            var input1Str = input1.Aggregate((i, j) => i + delimiter + j);
            var input2Str = input2.Aggregate((i, j) => i + delimiter + j);
    
            var myListStr = new List();
            myListStr.Add(input1Str);
            myListStr.Add(input2Str);
    
            myListStr.Sort();
            //Now you can convert it into List>
            List> myList = myListStr.Select(x => x.Split(',').ToList()).ToList();
    

提交回复
热议问题