【问题标题】:How to use the list.Contains() method in c# [duplicate]如何在c#中使用list.Contains()方法[重复]
【发布时间】:2017-12-16 21:55:09
【问题描述】:

我正在从下面的数据库中查询,但我只需要返回一个在 Agelist 中没有年龄的记录。但我被困在如何去尝试匹配表中的年龄和列表中的年龄。任何帮助都感激不尽。谢谢

List<int> AgeList = new List<int> { 61, 42, 23, 25 };
var query = Context.Table.FirstorDefault(t => t.Name == name && and t.Country ==country && t.Age != AgeList.Contains()) // I'm stuck here!!

【问题讨论】:

    标签: c#


    【解决方案1】:
    var query = Context.Table.FirstorDefault(t => t.Name == name && and t.Country ==country && !AgeList.Contains(t.Age))
    

    我想这就是你要找的东西

    【讨论】:

      【解决方案2】:

      它应该看起来像这样: AgeList.Contains(t.Age)。

      如果 int 列表有 t.Age ,它将返回 true ,否则将返回 false 。

      这里有一些关于 Contains 的文档:https://msdn.microsoft.com/fr-fr/library/bhkz42b3(v=vs.110).aspx

      【讨论】:

        猜你喜欢
        • 2010-09-28
        • 1970-01-01
        • 1970-01-01
        • 2011-09-28
        • 2011-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多