Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#列表-排序数据_C# - Fatal编程技术网

C#列表-排序数据

C#列表-排序数据,c#,C#,我试图将元素添加到一个列表中,对它们进行排序,然后输出它们,如果您愿意,每个列表都有许多“列” List<Info> infoList = new List<Info>(); while (dr.Read()) { meeting_id = dr.GetValue(0).ToString(); try { Appointment appointment = Appointment.Bind(service, new ItemId(meet

我试图将元素添加到一个列表中,对它们进行排序,然后输出它们,如果您愿意,每个列表都有许多“列”

List<Info> infoList = new List<Info>();

while (dr.Read())
{

   meeting_id = dr.GetValue(0).ToString();
   try
   {
      Appointment appointment = Appointment.Bind(service, new ItemId(meeting_id));

      Info data = new Info();
      data.Start = appointment.Start;
      data.Fruit = Convert.ToInt32(dr.GetValue(1));
      data.Nuts = Convert.ToInt32(dr.GetValue(2));

      infoList.Add(data);

   }
您可以使用扩展名按特定顺序枚举集合(例如,按
Start
属性值排序):


考虑在数据库方面添加排序,这将是更有效的

谢谢,我不能排序数据库端的原因是没有从数据库中拉取开始日期。数据库中存储的唯一内容是会议ID(来自Outlook)、“水果”和“坚果”,然后我使用EWS从Exchange中提取开始时间。@CorbinSpicer我明白了。然后,您只能选择对内存中的集合进行排序
 for (int i = 0; i < infoList.Count; i++)
 {
     meet = meet + infoList[i];
 }   
public class Info
{
    public DateTime Start { get; set; }
    public int Fruit { get; set; }
    public int Nuts { get; set; }
}
foreach(var info in infoList.OrderBy(i => i.Start))
{
    // use info object here
    // info.Fruits
    // info.Nuts
}