我有一个基本类,我在其中定义了一些属性。
public class Cliente
{
public string ID { get; set; }
public string Nome { get; set; }
public string CPF { get; set; }
public string Email { get; set; }
public string Base { get; set; }
public bool Enviado { get; set; }
public Cliente(string id, string nome, string cpf, string email, string baseDados = "TV", bool enviado = false)
{
ID = id;
Nome = nome;
CPF = cpf;
Email = email;
Enviado = enviado;
Base = baseDados;
}
}
我的列表
List<Cliente> clientes = new List<Cliente>();
如何在此列表中选择可以访问该类属性的项目?
Cliente c = clientes.Select(x => x.Enviado == false);
我已经尝试过这种方式,但是 Select 返回一个 bool 值,对吗?我也尝试使用Where,但它不返回对象
最佳答案
您可以像这样使用FirstOrDefault
:
Cliente c = clientes.FirstOrDefault(x => !x.Enviado);
关于c# - 从列表中选择一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48911545/