亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何按 C# 列表排序,以便重復項以其插入的相反順序出現

如何按 C# 列表排序,以便重復項以其插入的相反順序出現

C#
搖曳的薔薇 2021-06-24 18:05:03
如何按列表排序,使重復項以插入的相反順序出現(考慮到我不會使用列表的插入方法在中間插入任何項)以下面的例子為例:public class Program{    public static void Main(string[] args)    {        List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();        list.Add(new KeyValuePair<int, string>(1, "A"));        list.Add(new KeyValuePair<int, string>(3, "F"));        list.Add(new KeyValuePair<int, string>(4, "G"));        list.Add(new KeyValuePair<int, string>(2, "B"));        list.Add(new KeyValuePair<int, string>(2, "C"));        list.Add(new KeyValuePair<int, string>(3, "E"));        list.Add(new KeyValuePair<int, string>(3, "D"));        list=list.OrderBy(a=>a.Key).ToList();        foreach(var item in list)        {            Console.WriteLine(item);        }    }}輸出:[1, A][2, B][2, C][3, F][3, E][3, D][4, G]我希望重復的順序與插入的順序相反,例如 F、E、D 應顯示為 D、E、F。我雖然 orderByDescending 可以解決問題,但這也會保持插入的順序。
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 193 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號