Click here to Skip to main content
15,888,968 members

Survey Results

"out" parameters: A good idea or a bad idea?

Survey period: 15 Jan 2018 to 22 Jan 2018

Given that it has its own Code Analysis warning we know where some people stand on this.

OptionVotes% 
They are a Good Thing1029.66
They are fine if used wisely43240.91
They are what they are15414.58
They should probably be avoided where possible20119.03
They should never be used. Ever.393.69
I have no idea.12812.12



 
GeneralI prefer to avoid them Pin
den2k8818-Jan-18 2:52
professionalden2k8818-Jan-18 2:52 
GeneralManipulating struct-arrays directly. Pin
Paulo Zemek17-Jan-18 8:19
mvaPaulo Zemek17-Jan-18 8:19 
To me, the best use of ref and out is to manipulate arrays of structs avoiding a copy and avoiding doing things like

array[i].Key = 1;
array[i].Value = 2;

About the TryParse, I really think doing it with nullable types (or returning null to class-types) does a better job.

Edit: Also, because of how variance works and the inner details of how out is implemented, out parameters can't be an "out T". This makes it impossible to declare a bool TryGetValue(TKey key, out TValue) having TValue to be "out TValue".
So, even if you want a TryGetValue to have an out parameter, it is best declared as:
TValue TryGetValue(TKey key, out bool found);
This way, you can declare TValue itself as out.
GeneralLike so many things.... Pin
Dominic Burford17-Jan-18 4:51
professionalDominic Burford17-Jan-18 4:51 
Answernot more than one ref- or out parameter Pin
sx200816-Jan-18 7:17
sx200816-Jan-18 7:17 
Generalno idea or opinion on the matter Pin
Dennis E White16-Jan-18 4:33
professionalDennis E White16-Jan-18 4:33 
GeneralThey are ok if you know what you are doing Pin
RugbyLeague15-Jan-18 21:08
RugbyLeague15-Jan-18 21:08 
GeneralRe: They are ok if you know what you are doing Pin
obermd16-Jan-18 4:39
obermd16-Jan-18 4:39 
GeneralRe: They are ok if you know what you are doing Pin
Foothill16-Jan-18 4:56
professionalFoothill16-Jan-18 4:56 
GeneralThey are what they are Pin
CPallini15-Jan-18 9:33
mveCPallini15-Jan-18 9:33 
GeneralRe: They are what they are Pin
Nemanja Trifunovic18-Jan-18 2:23
Nemanja Trifunovic18-Jan-18 2:23 
GeneralWith tuples, I think they are mostly unnecessary Pin
Marc Clifton15-Jan-18 7:07
mvaMarc Clifton15-Jan-18 7:07 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
OriginalGriff15-Jan-18 11:20
mveOriginalGriff15-Jan-18 11:20 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Richard Deeming16-Jan-18 3:48
mveRichard Deeming16-Jan-18 3:48 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Slacker00716-Jan-18 4:21
professionalSlacker00716-Jan-18 4:21 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Stuart Dootson16-Jan-18 1:12
professionalStuart Dootson16-Jan-18 1:12 
GeneralRe: With tuples, I think they are mostly unnecessary Pin
Mel Padden16-Jan-18 2:43
Mel Padden16-Jan-18 2:43 
GeneralThey are just fine, if used wisely Pin
Slacker00715-Jan-18 3:37
professionalSlacker00715-Jan-18 3:37 
GeneralRe: They are just fine, if used wisely Pin
peterchen15-Jan-18 4:46
peterchen15-Jan-18 4:46 
GeneralRe: They are just fine, if used wisely Pin
Espen Harlinn15-Jan-18 5:01
professionalEspen Harlinn15-Jan-18 5:01 
GeneralRe: They are just fine, if used wisely Pin
Dirk Bahle15-Jan-18 5:24
Dirk Bahle15-Jan-18 5:24 
GeneralRe: They are just fine, if used wisely Pin
peterchen15-Jan-18 5:32
peterchen15-Jan-18 5:32 
GeneralC# TryParse() PinPopular
PeejayAdams15-Jan-18 0:55
PeejayAdams15-Jan-18 0:55 
GeneralRe: C# TryParse() Pin
Slacker00715-Jan-18 3:33
professionalSlacker00715-Jan-18 3:33 
GeneralRe: C# TryParse() Pin
PeejayAdams15-Jan-18 4:33
PeejayAdams15-Jan-18 4:33 
GeneralRe: C# TryParse() Pin
11917640 Member 15-Jan-18 5:30
11917640 Member 15-Jan-18 5:30 

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.