C# 如何更新自定义类对象中字段的值

C# 如何更新自定义类对象中字段的值,c#,windows,class,xaml,C#,Windows,Class,Xaml,我正在尝试更改类对象中的值。是否有任何更改。我正在尝试在UI中动态显示更新。(xaml) 我的班级: public class Students { public int id; public string Name; public int Age; } //Students studs = new Students(); public ObservableCollection<Students> studs = new ObservableCol

我正在尝试更改类对象中的值。是否有任何更改。我正在尝试在UI中动态显示更新。(xaml)

我的班级:

 public class Students
 {
    public int id;
    public string Name;
    public int Age; 
 }


//Students studs = new Students();
public ObservableCollection<Students> studs = new ObservableCollection<Students>();
Students studs_temp = sender as Students; // Read data in tapped function
int index = studs.IndexOf();
//Here I need to alter the Age of Student in studs where the id
 is equal to  id in studs_temp.
公共班级学生
{
公共int id;
公共字符串名称;
公共信息;
}
//学生=新生();
公共ObservableCollection螺柱=新ObservableCollection();
Students_temp=作为学生的发件人;//在抽头函数中读取数据
int index=studs.IndexOf();
//在这里,我需要改变学生的年龄,其中id
等于螺柱温度中的id。
类似这样的内容:

public class Student
{
    public int id;
    public string Name;
    public int Age; 
}
在您的消费方式中:

List<Student> students = new List<Student>();
// ...
// populate your list
// ...

// select the student with a particular ID
Student s = students.Single(x => x.id == myID);
// now alter the age of that student
s.Age = 23;
List students=newlist();
// ...
//填充您的列表
// ...
//选择具有特定ID的学生
Student s=students.Single(x=>x.id==myID);
//现在改变那个学生的年龄
s、 年龄=23岁;

分配你可以像stud1.age=stud2.age这样的assing有什么问题?…我在studs中添加了几个对象,我需要编辑一个特定id的年龄,Ans studs被声明为globalyFirst你可能想将你的类重命名为
Student
意味着一个实例正好是一个学生。因此,您需要另一种结构来存储学生列表,例如
列表
,您可以在其中使用给定的
ID
搜索该学生。。我编辑了这个问题