This project is read-only.

TryParseOrDefaultTo

Topics: C# Language Design, VB Language Design
Sep 18, 2014 at 7:14 PM
I have of late been wondering why the framework hasn't got a method like TryParseOrDefaultTo instead of writing code over and over that looks like:-

int defaultValue = -1;
return int.TryParse( s , out defaultValue ) ? defaultValue : defaultValue;

I would personally love to see this as an addition to the BCL; it would save our poor fingers a few lines of typing :D
Sep 19, 2014 at 1:43 AM
HornerG wrote:
I would personally love to see this as an addition to the BCL; it would save our poor fingers a few lines of typing :D
Which makes I not a language feature.

Are you aware that the result of that code is 0 and not -1 if the parsing fails?