簡體   English   中英

如何更新自定義類對象中字段的值

[英]How to update the value of a field in a custom class object

我正在嘗試更改類對象中的值。有沒有這樣做。我正在嘗試在 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.

像這樣的東西:

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM