how to check if List element contains an item with a Particular Property Value

前端 未结 6 883
野的像风
野的像风 2020-12-07 11:54
public class PricePublicModel
{
    public PricePublicModel() { }

    public int PriceGroupID { get; set; }
    public double Size { get; set; }
    public double S         


        
6条回答
  •  我在风中等你
    2020-12-07 12:38

    You don't actually need LINQ for this because List provides a method that does exactly what you want: Find.

    Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire List.

    Example code:

    PricePublicModel result = pricePublicList.Find(x => x.Size == 200);
    

提交回复
热议问题