我知道有很多这样的问题,但它们并不能解决我的问题。我很新,不太了解。
我的问题是我想从一个值中获取整个键和值。
我的字典
public Dictionary<string, (int Position, string Name, int Hp, int Power, int Agility)> Player1Inventory = new Dictionary<string, (int Position, string Name, int Hp, int Power, int Agility)>
{
["contentCube"] = (Position: 1, Name: "ContentCube", Hp: 200, Power: 100, Agility: 70),
};
Run Code Online (Sandbox Code Playgroud)
我需要根据他的职位获取所有信息。我在其他类似问题上发现使用 Linq,但他们给出的示例对我不起作用。
我发现但不起作用的示例:
var myKey = types.FirstOrDefault(x => x.Value == "one").Key;
Run Code Online (Sandbox Code Playgroud)
和
var keysWithMatchingValues = dic.Where(p => p.Value == "a").Select(p => p.Key);
Run Code Online (Sandbox Code Playgroud)
任何帮助或解释表示赞赏。