fork(34) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<Student> myList = new List<Student>();
  10. myList.Add(new Student("John", 10));
  11. myList.Add(new Student("Tom", 20));
  12. foreach ( var tom in myList.Where(w => w.Name == "Tom")) {
  13. tom.Marks = 35;
  14. }
  15. foreach ( var s in myList) {
  16. Console.WriteLine("Name='{0}, Marks={1}", s.Name, s.Marks);
  17. }
  18. }
  19. }
  20.  
  21. class Student {
  22. private string name;
  23. private int marks;
  24. public string Name { get; set;}
  25. public int Marks { get; set; }
  26. public Student(string name, int marks) {
  27. Name = name;
  28. Marks = marks;
  29. }
  30. }
Success #stdin #stdout 0.04s 24312KB
stdin
Standard input is empty
stdout
Name='John, Marks=10
Name='Tom, Marks=35