我试图让下面的方法签名工作.因为这是一个匿名类型我有一些麻烦,任何帮助都会很棒.
当我在QuickWatch窗口中查看sortedGameList.ToList()时,我得到了签名
System.Collections.Generic.List<<>f__AnonymousType0>>
非常感谢
唐纳德
public List> getGamesList(int leagueID) { var sortedGameList = from g in Games group g by g.Date into s select new { Date = s.Key, Games = s }; return sortedGameList.ToList(); }
leppie.. 6
选择新的{Date = s.Key,Games = s.ToList()};
编辑:那错了!我认为这样做.
public List> getGamesList(int leagueID) { var sortedGameList = from g in Games group g by g.Date; return sortedGameList.ToList(); }
不,你不需要选择!
选择新的{Date = s.Key,Games = s.ToList()};
编辑:那错了!我认为这样做.
public List> getGamesList(int leagueID) { var sortedGameList = from g in Games group g by g.Date; return sortedGameList.ToList(); }
不,你不需要选择!
您不应该返回匿名实例.
您无法返回匿名类型.
创建一个类型(命名)并返回:
public class GameGroup { public DateTime TheDate {get;set;} public ListTheGames {get;set;} }
//
public ListgetGamesGroups(int leagueID) { List sortedGameList = Games .GroupBy(game => game.Date) .OrderBy(g => g.Key) .Select(g => new GameGroup(){TheDate = g.Key, TheGames = g.ToList()}) .ToList(); return sortedGameList; }