Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# DataTable列值分组和排序_C#_Linq_Sorting_Datatable_Grouping - Fatal编程技术网

C# DataTable列值分组和排序

C# DataTable列值分组和排序,c#,linq,sorting,datatable,grouping,C#,Linq,Sorting,Datatable,Grouping,DataTable的列A包含3种类型的内容: 数字的 字母数字 字母表 数据表的列B包含日期格式“YYYYMMDD” 我需要根据3种内容类型对数据进行分组,然后按日期升序排序 例如: ColumnA | ColumnB A123457 | 20171114 B246734 | 20171009 1234544 | 20170808 6789033 | 20171220 ABBCDEE | 20180102 A112233 | 20160202 1212122 | 20171115 NNNNNN

DataTable的列A包含3种类型的内容:

  • 数字的
  • 字母数字
  • 字母表
  • 数据表的
    列B
    包含日期格式“YYYYMMDD

    我需要根据3种内容类型对数据进行分组,然后按日期升序排序

    例如:

    ColumnA | ColumnB A123457 | 20171114 B246734 | 20171009 1234544 | 20170808 6789033 | 20171220 ABBCDEE | 20180102 A112233 | 20160202 1212122 | 20171115 NNNNNNN | 20171011
    我们将为此提供什么样的LINQ解决方案

    下面不是确切的代码,通过下面的方法您可以达到预期的结果

    //sort the date and put into same list
    CultureInfo provider = CultureInfo.InvariantCulture;
                        myList.ForEach(i => { i.ColumnB = DateTime.ParseExact(i.ColumnB, "YYYYMMDD", provider);});
    
    //check for regex match and add to list
                        mynumericlist = myList.Where(x => Regex.IsMatch(x.columnA, @"^\d$")).ToList().OrderBy(x=>x.ColumnB);
                        myalphalist = myList.Where(x => Regex.IsMatch(x.columnA, @"^[a-zA-Z]*$")).ToList().OrderBy(x => x.ColumnB);
                        myalpnumlist = myList.Where(x => Regex.IsMatch(x.columnA, @"^[a-zA-Z0-9]*$")).ToList().OrderBy(x => x.ColumnB);
    
                        //then combine all
    

    这里的答案是否有帮助:@jason.kaisersmith,谢谢你指出,但这个要求有点不同。
    //sort the date and put into same list
    CultureInfo provider = CultureInfo.InvariantCulture;
                        myList.ForEach(i => { i.ColumnB = DateTime.ParseExact(i.ColumnB, "YYYYMMDD", provider);});
    
    //check for regex match and add to list
                        mynumericlist = myList.Where(x => Regex.IsMatch(x.columnA, @"^\d$")).ToList().OrderBy(x=>x.ColumnB);
                        myalphalist = myList.Where(x => Regex.IsMatch(x.columnA, @"^[a-zA-Z]*$")).ToList().OrderBy(x => x.ColumnB);
                        myalpnumlist = myList.Where(x => Regex.IsMatch(x.columnA, @"^[a-zA-Z0-9]*$")).ToList().OrderBy(x => x.ColumnB);
    
                        //then combine all