C#C
C#4y ago
9 replies
Matt

❔ Check if list contains object with a specific property/variable value

I have a list of Players where Player is a simple object with a Name and ID. I need to check to see if a player with a specific ID is on the player list. I know that I could use a dictionary to do this but if there is a way to keep the list, that would be ideal. Here's a rough outline of what I'm trying to achieve
class Player
{
  public string Name;
  public ushort Id;
      
  public Player(string name, ushort id)
  {
    Name = name;
    Id = id;
  }
}

class PlayerHandler
{
  public static List<Player> Players = new();
  
  public static void GetPlayer(ushort id)
  {
    if(Players.Contains()) return Player
  }  
}
Was this page helpful?