public class PricePublicModel
{
public PricePublicModel() { }
public int PriceGroupID { get; set; }
public double Size { get; set; }
public double Size2 { get; set; }
public int[] PrintType { get; set; }
public double[] Price { get; set; }
}
List<PricePublicModel> pricePublicList = new List<PricePublicModel>();
How to check if element of pricePublicList
contains certain value. To be more precise, I want to check if there exists pricePublicModel.Size == 200
? Also, if this element exists, how to know which one it is?
EDIT If Dictionary is more suitable for this then I could use Dictionary, but I would need to know how :)
This is pretty easy to do using LINQ:
You can using the exists
If you have a list and you want to know where within the list an element exists that matches a given criteria, you can use the
FindIndex
instance method. Such asWhere
f => f.Bar == 17
is a predicate with the matching criteria.In your case you might write
You don't actually need LINQ for this because
List<T>
provides a method that does exactly what you want:Find
.Example code: