我对我正在做的一个小项目有疑问。我目前有一个listBox,其中填充了#39; Game'类型的对象。在游戏中,有Name,GameConsole,Genre等属性......
我想根据这些属性过滤我的结果。我想知道这是否可能。我通过Access数据库中的DA类获取我的游戏对象。
我用这段代码从DA中获取我的游戏:
listBoxGames.BeginUpdate();
DAGame daGame = new DAGame();
List<Game> games = daGame.GetGames();
foreach (Game game in games)
{
listBoxGames.Items.Add(game);
}
listBoxGames.EndUpdate();
编辑:这是我的游戏对象的声明
public Game(int id, string naam, string afbeelding, float score, string opmerkingen, bool online, bool coOp, int maxAantalSpelers, int multiplayerTypeId, int systeemId, int genreId, int jaar, bool touchControls, string uitgeleend, bool favoriet)
{
this.Id = id;
this.Naam = naam;
this.Afbeelding = afbeelding;
this.Score = score;
this.Opmerkingen = opmerkingen;
this.Online = online;
this.CoOp = coOp;
this.MaxAantalSpelers = maxAantalSpelers;
this.MultiplayerTypeId = multiplayerTypeId;
this.SysteemId = systeemId;
this.GenreId = genreId;
this.Jaar = jaar;
this.TouchControls = touchControls;
this.Uitgeleend = uitgeleend;
this.Favoriet = favoriet;
}
提前致谢
答案 0 :(得分:1)
这可以帮助我思考。
listBoxGames.BeginUpdate();
DAGame daGame = new DAGame();
List<Game> games = daGame.GetGames();
foreach (Game game in games)
{
listBoxGames.Items.Add(game.Where(x => x.Name.Equals("ThisName").Single());
}
listBoxGames.EndUpdate();
答案 1 :(得分:0)
这可能就是你想要的
var nameFilterList=games.Where(x=>x.Name="SomeName").ToList();