using System; public class Test { private static bool TryParseOf(string s, out TType result) { if (typeof(TType) == typeof(int)) { var parseSuccessful = int.TryParse(s, out int innerResult); result = (TType)(object)innerResult; return parseSuccessful; } throw new NotImplementedException(); } public static void Main() { Console.WriteLine("{0}: {1}", TryParseOf1("123", out var x), x); } }