using System;
using System.Linq;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
List<Student> myList = new List<Student>();
myList.Add(new Student("John", 10));
myList.Add(new Student("Tom", 20));
foreach ( var tom in myList.Where(w => w.Name == "Tom")) {
tom.Marks = 35;
}
foreach ( var s in myList) {
Console.WriteLine("Name='{0}, Marks={1}", s.Name, s.Marks);
}
}
}
class Student {
private string name;
private int marks;
public string Name { get; set;}
public int Marks { get; set; }
public Student(string name, int marks) {
Name = name;
Marks = marks;
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJTGlzdDxTdHVkZW50PiBteUxpc3QgPSBuZXcgTGlzdDxTdHVkZW50PigpOwogICAgICAgIG15TGlzdC5BZGQobmV3IFN0dWRlbnQoIkpvaG4iLCAxMCkpOwogICAgICAgIG15TGlzdC5BZGQobmV3IFN0dWRlbnQoIlRvbSIsIDIwKSk7CiAgICAgICAgZm9yZWFjaCAoIHZhciB0b20gaW4gbXlMaXN0LldoZXJlKHcgPT4gdy5OYW1lID09ICJUb20iKSkgewogICAgICAgICAgICB0b20uTWFya3MgPSAzNTsKICAgICAgICB9CiAgICAgICAgZm9yZWFjaCAoIHZhciBzIGluIG15TGlzdCkgewogICAgICAgIAlDb25zb2xlLldyaXRlTGluZSgiTmFtZT0nezB9LCBNYXJrcz17MX0iLCBzLk5hbWUsIHMuTWFya3MpOwogICAgICAgIH0KCX0KfQoKY2xhc3MgU3R1ZGVudCB7CiAgICBwcml2YXRlIHN0cmluZyBuYW1lOwogICAgcHJpdmF0ZSBpbnQgbWFya3M7CiAgICBwdWJsaWMgc3RyaW5nIE5hbWUgeyBnZXQ7IHNldDt9CiAgICBwdWJsaWMgaW50IE1hcmtzIHsgZ2V0OyBzZXQ7IH0KICAgIHB1YmxpYyBTdHVkZW50KHN0cmluZyBuYW1lLCBpbnQgbWFya3MpIHsKICAgICAgICBOYW1lID0gbmFtZTsKICAgICAgICBNYXJrcyA9IG1hcmtzOwogICAgfQp9