开发者

How to update the content inside a list in c#

开发者 https://www.devze.com 2023-03-31 23:15 出处:网络
I have a class as follow: public class student { public string studentID { get; set; } public string studentName { get; set; }

I have a class as follow:

public class student
{
  public string studentID { get; set; }
  public string studentName { get; set; }
  public string studentGender { get; set; }
  public string studen开发者_开发技巧tCGP { get; set; }
}

List<student> students = new List<student>();

..... I had added some data into the students List mention above, except for the data to the studentCGP.

After my other calculation for the studentCGP data, how do I put the data back to respectively? I'll have the studentID and studentCGP in hand.


using Linq...

var student = students.Find( x => x.studentID == idValue );
student.studentCGP = cgpValue;

Seems pretty trivial... am I missing something in the question?


students.Single(o => o.studentID == idValue).studentCGP = cgpValue;

There is a number of functions that you can use, just choose the one that suits you the best. For example you can use also First, Last etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消