Readonly primary constructor backing fields #18975
                  
                    
                      thinkbeforecoding
                    
                  
                
                  started this conversation in
                Ideas
              
            Replies: 1 comment 1 reply
-
| 
         The mechanism around IL's  The F# record's field was on the IL level  = Right now, I do not see why not  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that in C#, primary constructor's parameters are mutable. To make them readonly, they have to be stored in a readonly fiels, in which case, the primary constructor's parameters backing field disapear:
compiles as:
while
compiles as:
Since parameters are readonly (immutable) in F#, I expected them to be stored in a readonly field:
but this is not the case:
Why is the field mutable ? Would it be a breaking change to make it readonly ?
(readonly fields can help the JIT to do better optimizations...)
Beta Was this translation helpful? Give feedback.
All reactions