我有以下类(class):
public class Customer
{
public int location { get; set; }
public List<int> slots { get; set; }
}
然后我有一个客户列表:
List<Customer> lstCustomer = new List<Customer>();
然后我有一个插槽号:
int slot = 4;
我想返回插槽所属的特定位置的整数。 (见上面的客户类别)
这是我目前所拥有的:
int? location = lstCustomer
.Where(l => l.slots.Any(x => slot))
.FirstOrDefault();
但这不起作用(错误:无法将 int 转换为 bool
)。任何帮助,将不胜感激。谢谢。
最佳答案
int? location = lstCustomer.FirstOrDefault(x => x.slots.Contains(slot))?.location;
关于c# - 使用lambda C#从列表中的列表返回一个整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50511262/