3 ms·
All the same: int Foo => 4; private int Foo { get => 4; } private int Foo { get { return 4; } }
by ludston 3y ago
All the same:
int Foo => 4;
private int Foo { get => 4; }
private int Foo { get { return 4; } }
- thefz 3y agoDo these all compile to the exact same thing? https://sharplab.io/#v2:CYLg1APgAgTAjAWAFBQMwAJboMLoN7LpHoCWAdgC7oBiA9regLwB86ALANzKHEAOATiQBuAQwoBTUpRr0Y+dAHNxVFuw7oAvtyTF0A4WMnkqdWhjyLl8qAHY1mhzyJPMGKG3QBZABQBKfC5aSBpAA=== https://sharplab.io/#v2:CYLg1APgAgTAjAWAFBQMwAJboMLoN7LpHoCW... Yes, so you are right. I don't get why in IL, the expression bodied member is different, though. Still, makes sense if you have learned C# starting from the most verbose form (3) then (2) was introduced, then (1).
- ludston 3y agoI could probably give 20 different examples of this too. Not all of them would have identical compiler output, but the behaviour would be. E.g. you could add private int Foo { get; } = 4; To the above example given that the behaviour is identical, although the compiled output should be different so I didn't to avoid any nit pickers.