筛选列表框中对象的属性

本文关键字:属性 对象 列表 筛选 | 更新日期: 2023-09-27 17:54:59

我有一个关于我正在做的小项目的问题。我现在有一个列表框,里面装满了"游戏"类型的对象。在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;
}

Thanks in advance

筛选列表框中对象的属性

我想这可能有帮助。

 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();

这可能是你想要的

 var nameFilterList=games.Where(x=>x.Name="SomeName").ToList();
相关文章: