Click here to Skip to main content
15,892,298 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: Pinheads Pin
Wendelius21-Feb-22 4:41
mentorWendelius21-Feb-22 4:41 
GeneralRe: Pinheads Pin
trønderen21-Feb-22 7:10
trønderen21-Feb-22 7:10 
GeneralRe: Pinheads Pin
DougInNC222-Feb-22 2:38
DougInNC222-Feb-22 2:38 
GeneralRe: Pinheads Pin
OriginalGriff22-Feb-22 3:20
mveOriginalGriff22-Feb-22 3:20 
GeneralI have so few one-line methods... PinPopular
#realJSOP20-Feb-22 23:18
mve#realJSOP20-Feb-22 23:18 
GeneralRe: I have so few one-line methods... Pin
musefan20-Feb-22 23:29
musefan20-Feb-22 23:29 
GeneralRe: I have so few one-line methods... Pin
OriginalGriff21-Feb-22 1:40
mveOriginalGriff21-Feb-22 1:40 
GeneralRe: I have so few one-line methods... Pin
#realJSOP21-Feb-22 23:36
mve#realJSOP21-Feb-22 23:36 
For my MVVM code, pretty much all of my set methods look like this:

C#
get { return this.property; } set { if (value != this.property) { this.property = value; this.NotifyPropertyChanged(); } }


Doing it this way gains me nothing.

C#
get => this.property; set => if (value != this.property) { this.property = value; this.NotifyPropertyChanged(); }


There is no tangible reason or benefit to use this construct. At all.

Even if we were using .Net5+ at work, I won't be adopting this...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

AnswerRe: I have so few one-line methods... Pin
Bruce Greene22-Feb-22 5:34
Bruce Greene22-Feb-22 5:34 
GeneralRe: I have so few one-line methods... Pin
Wendelius22-Feb-22 8:35
mentorWendelius22-Feb-22 8:35 
GeneralSwift is topping that easy Pin
KarstenK20-Feb-22 21:30
mveKarstenK20-Feb-22 21:30 
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 PinPopular
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 
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.