c# - 包含 Linq

标签 c# linq linq-to-objects

我有类“Estimation”,这个类有一个属性“EstimationItems”(类型是 IList)

public class EstimationItem 
{
    public virtual int Id { get; set; }
    public virtual Product Product { get; set; }
    public virtual int Quantity { get; set; }
    public virtual decimal Price { get; set; }
}

public class Product 
{
    public virtual int Id { get; set; }
    public virtual string Code { get; set; }
    public virtual string Name { get; set; }
}

当我有一个“Estimation”实例时,我想知道“EstimationItems”是否包含代码为“MyCode”的产品。

最佳答案

使用这个:

List<EstimationItem> items = new List<EstimationItem>();
// Add items

int searchedCode = 1

if(items.Any(i => i.Product.Code == searchedCode))
{
    // Contained
}

关于c# - 包含 Linq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6486706/

相关文章:

c# - 如果值与当前属性相同,INotifyPropertyChanged 标准实现是否包含空操作?

c# - 在linq中生成具有步长的数字序列

c# - LINQ - SkipWhile 坏了吗?

javascript - 使用 jquery AJAX 的 POST 调用不起作用

c# - 在 C# 中获取给定线程的 cpu 号

c# - 如何在没有依赖关系的情况下读取 WCF 服务中的多部分/表单数据发布流

.net - 带有 RX 扩展的 LINQ

.net - 给出一个数字以返回 Enum 的近似值?

c# - 使用 SortedDictionary TakeWhile 返回空

c# - 使用 LINQ 获取下一个可用整数