c# - Lambda expression not return correct result when using All() -
i have class:
public class change() { public int id {get; set;} public decimal price {get; set;} } and have 2 lists oldprices , newprices. both lists contain same items albeit different instances.
some items in newprices have different prices, list of changed prices i'm doing:
var list = newprices .where(x => oldprices.all(p => p.price != x.price)) .todictionary(x => x.id, x => x.price); this expression should correct list empty though there changes.
what missing?
enumerable.all returns true if conditions true. that's not want check. want new-prices differ old-prices.
you have join both lists id first able compare prices:
var joined = np in newprices join op in oldprices on np.id equals op.id np.price != op.price select np; var newpricesbyid = joined.todictionary(p => p.id, p => p.price);
Comments
Post a Comment