0

の結果に応じてリストを並べたい

if(group.Substring(group.Length-1,1)%2==0)

降順 else 昇順

List<CellTemp> orderedCells = 
        (from shelf in foundCells
         where Convert.ToInt32(shelf.Group.Substring(shelf.Group.Length - 1), 1) % 2 == 0
         orderby shelf.Grup, shelf.Row descending
         select new CellTemp()
         {
             cod= shelf.cod,
             PN = shelf.PN,
             Description = shelf.Description,
             Group= shelf.Group,
             Row= shelf.Row,
             Shelf= shelf.Shelf
         }).ToList();

shell.Group が奇数か偶数かに応じて、最初の shelf.Group OrderBy と OrderBy の Shelf.row を昇順または降順に保つにはどうすればよいですか?

shell.group のフォーマットは「Group_A0」です。

--------------------編集-------------------------------

混乱させて申し訳ありません。私はこのようなことをしたいです。

var orderCells = (from shelf in celuleGasite
  where Convert.ToInt32(shelf.Gruup.Substring(shelf.Group.Length - 1, 1)) % 2 == 0
  orderby shelf.Group, shelf.Row descending
  where Convert.ToInt32(shelf.Group.Substring(shelf.Group.Length - 1, 1)) % 2 == 1
  orderby shelf.Group, shelf.Row ascending 
  select shelf).ToList();

しかし、リストには0要素があります

4

2 に答える 2

2

多分これはあなたが望むものです:

 var orderCells = (from shelf in celuleGasite
     where Convert.ToInt32(shelf.Group.Substring(shelf.Group.Length - 1, 1)) % 2 == 0
     orderby shelf.Group, shelf.Row descending)
     .Concat(from shelf in celuleGasite
             where Convert.ToInt32(shelf.Group.Substring(shelf.Group.Length - 1, 1)) % 2 == 1
             orderby shelf.Group, shelf.Row)
     .ToList();

または使用GroupBy

var orderCells = celuleGasite.GroupBy(shelf=>Convert.ToInt32(shelf.Group[shelf.Group.Length-1]) % 2)
                             .Select(g=>g.Key == 0 ? g.OrderBy(shelf=>shelf.Group)
                                                      .ThenByDescending(shelf=>shelf.Row) :
                                                     g.OrderBy(shelf=>shelf.Group)
                                                      .ThenBy(shelf=>shelf.Row))
                             .SelectMany(x=>x)
                             .ToList();
于 2013-08-10T23:58:28.603 に答える