Delegate as first param to an Extension Method
Ladies and Gents, I recently tried this experiment: static class TryParseExtensions { public delegate bool TryParseMethod<T>(string s, out T maybeValue); public static T? OrNull<T>(this TryParseMethod<T> tryParser, string s) where T:struct { T result; return tryParser(s, out result) ? (T?)result : null; } } // compiler error "'int.TryParse(string, out int)' is a 'method', which is not valid in the given context" var result = int.TryParse.OrNull("1"); // int.TryParse.OrNull<int>("1"); doesnt work either // compiler error: type cannot be infered....why? var result2 = TryParseExtensions.OrNull