fork download
  1. using System;
  2. using System.Collections.ObjectModel;
  3.  
  4. class How {
  5. public ObservableCollection<int> Coll {
  6. get { return coll_; }
  7. set {
  8. Console.WriteLine("Setter for Coll Called!");
  9. coll_.Clear();
  10. foreach (int i in value)
  11. coll_.Add(i);
  12. }
  13. }
  14.  
  15. public string Field {
  16. get { return field_; }
  17. set {
  18. Console.WriteLine("Setter for field called");
  19. field_ = value;
  20. }
  21. }
  22.  
  23. // To confirm the internal coll_ is actually set
  24. public void Test() {
  25. foreach(int i in coll_)
  26. Console.Write(i + " ");
  27. }
  28.  
  29. public How() {
  30. coll_ = new ObservableCollection<int>();
  31. field_ = "";
  32. }
  33.  
  34. private ObservableCollection<int> coll_;
  35. private string field_;
  36. }
  37.  
  38. public class Test {
  39. public static void Main() {
  40. var how = new How {
  41. Coll = { 1, 2, 3, 4, 5 },
  42. Field = "Test Field",
  43. };
  44.  
  45. Console.Write("Coll: ");
  46. foreach (int i in how.Coll)
  47. Console.Write(i + " ");
  48. Console.WriteLine();
  49.  
  50. Console.WriteLine("Field: " + how.Field);
  51.  
  52. Console.Write("Internal coll_: ");
  53. how.Test();
  54. Console.WriteLine();
  55. }
  56. }
Success #stdin #stdout 0.01s 29800KB
stdin
Standard input is empty
stdout
Setter for field called
Coll: 1 2 3 4 5 
Field: Test Field
Internal coll_: 1 2 3 4 5