Click here to Skip to main content
15,891,033 members

Survey Results

For the C# devs: expression body or old school functions?

Survey period: 21 Feb 2022 to 28 Feb 2022

Do you prefer the expression body public override string ToString() => "I am an object"; or the traditional public override string ToString() { return "I am a string"; }?

OptionVotes% 
I prefer the shortened expression body syntax13717.13
I prefer traditional functions31639.50
It depends on the situation18122.63
I don't care8911.13
I'd never heard of expression body definitions779.63



 
GeneralRe: Swift is topping that easy Pin
musefan20-Feb-22 23:22
musefan20-Feb-22 23:22 
GeneralRe: Swift is topping that easy Pin
KarstenK21-Feb-22 1:55
mveKarstenK21-Feb-22 1:55 
GeneralRe: Swift is topping that easy Pin
musefan21-Feb-22 2:55
musefan21-Feb-22 2:55 
GeneralRe: Swift is topping that easy Pin
KarstenK21-Feb-22 3:26
mveKarstenK21-Feb-22 3:26 
GeneralWhat a load of Pin
den2k8820-Feb-22 20:50
professionalden2k8820-Feb-22 20:50 
GeneralRe: What a load of Pin
Sammuel Miranda21-Feb-22 8:14
professionalSammuel Miranda21-Feb-22 8:14 
GeneralRe: What a load of Pin
Julian Ragan22-Feb-22 4:59
Julian Ragan22-Feb-22 4:59 
GeneralI prefer the shortened version, but it can be a pain. Pin
OriginalGriff20-Feb-22 19:14
mveOriginalGriff20-Feb-22 19:14 
It took me a while but I got used to it and now default to it.
But ... it can be a pain because if you start with an expression body UserControl constructor like this it's fine:
public MyControl() => InitializeComponent();
But when you need to add code to the body, you have to convert it to a "traditional" function:
public WordleLine()
     {
     InitializeComponent();
     ...
     }
But generally I try to use expression bodies throughout, when it's a single line of code.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

GeneralRe: I prefer the shortened version, but it can be a pain. Pin
Slacker00721-Feb-22 0:37
professionalSlacker00721-Feb-22 0:37 
GeneralRe: I prefer the shortened version, but it can be a pain. Pin
Rob Grainger23-Feb-22 4:21
Rob Grainger23-Feb-22 4:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.