>>>No, it has its place, I guess, but it could just as easily have returned an object with 2 properties.
>>
>>Don't see that as being so elegant. Compare:
internal class Program
>> {
>> private static void Main()
>> {
>> string s = "123";
>> int i;
>> if (!int.TryParse(s, out i))
>> {
>> //error
>> }
>>
>> TryParseReturnObject ret = JohnsTryParse(s);
>> if (!ret.success)
>> {
>> //Error
>> }
>> i = ret.result;
>> }
>>
>> private static TryParseReturnObject JohnsTryParse(string s)
>> {
>> int result;
>> bool success = int.TryParse(s, out result);
>> return new TryParseReturnObject{result = result,success = success};
>> }
>> }
>>
>> public class TryParseReturnObject
>> {
>> public int result { get; set; }
>> public bool success { get; set; }
>> }
>
>
>The Match object returned for RegEx uses your 'TryParseReturnObject' technique
>
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx>
>You get a Match back - and then you test its Success property
True but the Match class has to encapsulate many more properties.
>
>
>Personally I'm fine with TryXXX() methods - the reason they are there is to avoid an exception ( try/catch)
Presumably the TryParse() method is actually implemented as a Parse() within a try/catch anyway. So not more efficient - just easier to use......