Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串数组,我想根据单词的部分对其进行排序。例如,如果我将“comp”作为搜索词,它会按以“comp”开头的降序对数组进行排序,例如“compare”、“composition”、“computer”等。其余的词do not match 要么单独放置,要么按字母顺序排序(以更容易的为准)。
话虽如此,我可以用什么算法来解决这个问题?
这将选择您需要的单词并仅对这些单词进行排序:
var sortedWords = words.Where(x => x.Contains("comp")) .OrderByDescending(x => x);