Click here to Skip to main content
15,884,936 members
Home / Discussions / C#
   

C#

 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 5:41
professionalFoothill20-Apr-16 5:41 
GeneralRe: 'out' keyword, to use or not to use Pin
OriginalGriff20-Apr-16 6:22
mveOriginalGriff20-Apr-16 6:22 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 7:16
professionalFoothill20-Apr-16 7:16 
AnswerRe: 'out' keyword, to use or not to use Pin
Pete O'Hanlon19-Apr-16 23:01
mvePete O'Hanlon19-Apr-16 23:01 
GeneralRe: 'out' keyword, to use or not to use Pin
Nathan Minier20-Apr-16 1:51
professionalNathan Minier20-Apr-16 1:51 
GeneralRe: 'out' keyword, to use or not to use Pin
Pete O'Hanlon20-Apr-16 2:06
mvePete O'Hanlon20-Apr-16 2:06 
GeneralRe: 'out' keyword, to use or not to use Pin
Nathan Minier20-Apr-16 2:17
professionalNathan Minier20-Apr-16 2:17 
GeneralRe: 'out' keyword, to use or not to use Pin
Pete O'Hanlon20-Apr-16 2:36
mvePete O'Hanlon20-Apr-16 2:36 
The key part was my first sentence that it all depends on the context. My point there was that there are times when it's simpler and more appropriate to just return an "out" value, rather than having to contort yourself for the sake of purism. I deliberately focused on the OP's sample because the Try.... don't really need to do much more than they do. Now, suppose we wanted to extend the example, what about if we were looking to answer the question of why did it fail? Then it becomes more appropriate to return a struct/class.
C#
public class Parse<T>
{
  bool HasValue { get; set; }
  T Value { get; set; }
  string AdditionalInformation { get; set; }
}

This space for rent

GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 3:42
professionalFoothill20-Apr-16 3:42 
GeneralRe: 'out' keyword, to use or not to use Pin
Richard Deeming20-Apr-16 4:19
mveRichard Deeming20-Apr-16 4:19 
AnswerRe: 'out' keyword, to use or not to use Pin
Ian A Davidson20-Apr-16 0:09
Ian A Davidson20-Apr-16 0:09 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 4:34
professionalFoothill20-Apr-16 4:34 
QuestionWhile button is clicked Pin
tvks19-Apr-16 8:30
tvks19-Apr-16 8:30 
AnswerRe: While button is clicked Pin
clapclap19-Apr-16 8:32
clapclap19-Apr-16 8:32 
AnswerRe: While button is clicked Pin
koolprasad200319-Apr-16 18:26
professionalkoolprasad200319-Apr-16 18:26 
GeneralRe: While button is clicked Pin
CHill6020-Apr-16 1:25
mveCHill6020-Apr-16 1:25 
GeneralRe: While button is clicked Pin
koolprasad200320-Apr-16 1:33
professionalkoolprasad200320-Apr-16 1:33 
AnswerRe: While button is clicked Pin
CHill6020-Apr-16 2:14
mveCHill6020-Apr-16 2:14 
PraiseRe: While button is clicked Pin
tvks20-Apr-16 10:57
tvks20-Apr-16 10:57 
GeneralRe: While button is clicked Pin
CHill6020-Apr-16 11:01
mveCHill6020-Apr-16 11:01 
GeneralRe: While button is clicked Pin
tvks27-Apr-16 2:55
tvks27-Apr-16 2:55 
QuestionReflection and "security" Pin
Super Lloyd19-Apr-16 7:17
Super Lloyd19-Apr-16 7:17 
QuestionLinkButton isnt recognized properly Pin
Collectoons19-Apr-16 4:19
Collectoons19-Apr-16 4:19 
SuggestionRe: LinkButton isnt recognized properly Pin
Richard MacCutchan19-Apr-16 5:09
mveRichard MacCutchan19-Apr-16 5:09 
GeneralRe: LinkButton isnt recognized properly Pin
Collectoons19-Apr-16 5:16
Collectoons19-Apr-16 5:16 

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.