fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. struct RosterLine {
  5. public string RosCd;
  6. public string ActCd;
  7. public double Hrs;
  8. }
  9.  
  10. public class Test
  11. {
  12. public static void Main()
  13. {
  14. // your code goes here
  15. var dict = new SortedDictionary<DateTime, RosterLine>();
  16. dict.Add(DateTime.Today, new RosterLine());
  17. // Does not work as RosterLine is a value type
  18. dict[DateTime.Today].ActCd = "SO";
  19. // Works, but means a lot of copying
  20. var temp = dict[DateTime.Today];
  21. temp.ActCd = "SO";
  22. dict[DateTime.Today] = temp;
  23. }
  24. }
Compilation error #stdin compilation error #stdout 0.03s 33784KB
stdin
Standard input is empty
compilation info
prog.cs(18,21): error CS1612: Cannot modify a value type return value of `System.Collections.Generic.SortedDictionary<System.DateTime,RosterLine>.this[System.DateTime]'. Consider storing the value in a temporary variable
prog.cs(4,8): (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty