c# sorting a List<> using Tuple?

前端 未结 3 752
半阙折子戏
半阙折子戏 2021-01-12 05:24

I need to sort a List<> of MediaItem objects by publish date...the publish date is not a property of the item. So my initial intention was to temporarily tack on a publi

3条回答
  •  逝去的感伤
    2021-01-12 06:07

    List> list = new List>();
    
     for (int i = 0; i <= 10; i++)
     {
          DateTime date = new DateTime(2011, i, 1);
          MediaItem item = new MediaItem();
          list.Add(new Tuple(item, date));
     }
    
    list.Sort((a, b) => a.Item2.CompareTo(b.Item2));
    
    foreach (var element in list)
    {
        Console.WriteLine(element);
    }
    

提交回复
热议问题