mercredi 30 mars 2016

C# - check if list contains an object where a property equals value?

Is there a shorthand way to do it that does not involve loops?

public enum Item { Wood, Stone, Handle, Flint, StoneTool, Pallet, Bench  }

public struct ItemCount
{
    public Item Item;
    public int Count;
}

private List<ItemCount> _contents;

so something like:

if(_contents.Contains(ItemCount i where i.Item == Item.Wood))
{
    //do stuff
}





Aucun commentaire:

Enregistrer un commentaire