c# - 从 List<T> 获取项目并更新该项目的属性

标签 c#

我有一个 Person 类型的列表,我想根据 DisplayName 更新 DisplayValue。我怎样才能做到这一点?

public class Person
{
     public string DisplayName { get; set; }
     public string DisplayValue { get; set; }
     ... other properties
}

最佳答案

你的问题不清楚,但我认为这就是你所追求的。

List<Person> persons;
var person = persons.Find(p => p.DisplayName == "Fred");
person.DisplayValue = "Flinstone";

关于c# - 从 List<T> 获取项目并更新该项目的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5321174/

相关文章:

c# - 在 catch block 中返回?

c# - Windows如何获取已经运行的进程的进程组?

c# - 为什么在 lambda 中抛出异常是 C# 7 的一个特性?

c# - C# 中的 Yield Return - 对字段的公开进行失败测试

c# - 部署 NetFwTypeLib 以管理 Windows 防火墙

c# - linq-to-sql "Cannot remove an entity that has not been attached"

c# - 为什么我的图像在使用 iTextSharp 解码为 FlateDecode 时失真?

c# - 安装shield引用的项目dll

c# - .NET C# 设置由 lambda 选择器定义的字段的值

javascript - Asp .Net MVC5应用程序不会在setInterval方法中发送ajax请求