Andrew Zak
Andrew Zak

Reputation: 69

Select specific value from list class

I have the following list class

public class Users
{
    public string Username
    {
        get;
        set;
    }

    public string PlayerID
    {
        get;
        set;
    }
}

I was wondering how do I select the playerID where username = x ?

Upvotes: 0

Views: 1435

Answers (1)

Lee
Lee

Reputation: 144136

var player = playerList.FirstOrDefault(p => p.Username == "x");
if(player != null)
{
    string id = player.PlayerID;
}

Upvotes: 1

Related Questions