c# - 从列表中选择一个对象

标签 c# list

我有一个基本类,我在其中定义了一些属性。

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/

相关文章:

python - 如何为列表中的每个元素添加值?

python - 如何使用python将存储在列表中的像素转换为图像?

javascript - 过滤掉嵌套列表中具有特定键的字典元素

c# - 如何从 C# 中的特定光标点开始读取文件?

c# - vb.net 中的 IComparer 问题,但在 C# 中工作相同

c# - Action 延迟扩展方法不起作用

表单上的 C# 线程

c# - 您如何选择要调试的构建目标?

c# - 我应该为整数对使用什么数据结构?

c# - 按列名字符串对列表进行排序