Created
          January 2, 2014 02:34 
        
      - 
      
- 
        Save controlflow/8214142 to your computer and use it in GitHub Desktop. 
    Value type + readonly field...
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System; | |
| public struct S { | |
| int _value; | |
| public S(int value) { _value = value; } | |
| public int Value { get { return _value; } } | |
| public void Mutate() { _value++; } | |
| } | |
| public class C { | |
| S _s = new S(42); | |
| readonly S _r = new S(42); | |
| public static void Main() { | |
| var c = new C(); | |
| c._s.Mutate(); | |
| c._r.Mutate(); | |
| Console.WriteLine(c._s.Value); // 43 | |
| Console.WriteLine(c._r.Value); // 42 | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment