Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get F#'s constructor-parameters-are-automatically-immutable-private-members feature in C#?

In F#, the constructor parameters are automatically saved as immutable fields in the class without having to write the declaration of the field or the copying of the constructor parameter to the field in the constructor.

Is there any way to mimic this functionality in C#? Is there a reason why a future version of C# couldn't have this feature (i.e. is there some fundamental limitation of the existing language that conflicts with this feature)?

like image 547
Scott Whitlock Avatar asked Jun 21 '17 18:06

Scott Whitlock


People also ask

What chord can I substitute for F?

An F chord is formed with the notes F, A and C. We can play a simple triad shape across strings 4, 3 and 2. If I replace the A note on string 3 with the open G I create what is called an Fsus2. Adding an open string 1 to these shapes creates an Fmaj7 (commonly used by beginners to replace an F chord) or Fmaj7sus2.

Why is an F chord so hard?

The F chord is probably the hardest chord to learn for a beginner (Bb is probably second) because of the spacing between the frets (you have to really stretch your fingers), because the open version makes you put your hand in an awkward position, and the barre chord version really needs pressure by your index finger to ...


1 Answers

The C# equivalent will be records. These are currently earmarked for C# 8, but there's no guarantees (especially as they were proposed for C# 6 & 7 too and were delayed in both cases).

like image 109
David Arno Avatar answered Sep 30 '22 06:09

David Arno