Last active
August 29, 2015 14:07
-
-
Save jarrettmeyer/e69fdfb55f9e241f1a42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TryParseInt32Result | |
{ | |
private readonly bool _isSuccessful; | |
private readonly int _value; | |
public TryParseInt32Result(bool isSuccessful, int value) | |
{ | |
_isSuccessful = isSuccessful; | |
_value = value; | |
} | |
public bool IsSuccessful | |
{ | |
get { return _isSuccessful; } | |
} | |
public int Value | |
{ | |
get { return _value; } | |
} | |
} | |
public static TryParseInt32Result TryParse(string str) | |
{ | |
int value; | |
bool isSuccessful = TryParse(str, out value); | |
return new TryParseInt32Result(isSuccessful, value); | |
} | |
// Usage: | |
var result = System.Int32.TryParse("123"); | |
if (result.IsSuccessful) | |
{ | |
var theValue = result.Value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment