如何更新List<object>里某个对象的属性
1个回答
展开全部
。
List<student> s= new student()
{
new student {name ="11111",adress ="22222"},
new student {name ="22222",adress ="22222"},
new student {name ="33333",adress ="22222"}
}
正确的写法其实是这样的:
using System.Collections.Generic;
using System.Linq;
public static void Test()
{
var students = new List<Student>()
{
new Student {Name = "11111", Adress = "22222"},
new Student {Name = "22222", Adress = "22222"},
new Student {Name = "33333", Adress = "22222"}
};
var list = students.Where(o => o.Name == "22222").ToList();
foreach (var student in list)
{
student.Adress = "00000";
}
}
private class Student
{
public string Name { get; set; }
public string Adress { get; set; }
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询