我有以下课程:
public class Customer
{
public int location { get; set; }
public List<int> slots { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个客户列表:
List<Customer> lstCustomer = new List<Customer>();
Run Code Online (Sandbox Code Playgroud)
然后我有一个插槽号码:
int slot = 4;
Run Code Online (Sandbox Code Playgroud)
我想返回插槽所属的特定位置的整数.(见上面的客户类)
这是我到目前为止:
int? location = lstCustomer
.Where(l => l.slots.Any(x => slot))
.FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
但这不起作用(Error: Cannot convert int to bool).任何帮助,将不胜感激.谢谢.
int? location = lstCustomer.FirstOrDefault(x => x.slots.Contains(slot))?.location;
Run Code Online (Sandbox Code Playgroud)