object value;
     Parser.TryParse(typeof(int), "1", out value);

is a valid call to the second (non-generic method).


It would seem to me that it is then inferring T as object here ...

return TryParse(input, out value);

because if

   public static bool TryParse<T>(string input, out T value) value is
an object ... (and its a T) T must be an object.


What were you expecting to be the error and why?

Cheers,

Greg

On Fri, Apr 11, 2008 at 5:06 PM, Sébastien Lorion
<[EMAIL PROTECTED]> wrote:
> The following program outputs:
>
>  in Parse, type='System.Int32'
>  in Parse<T>, T='System.Object'
>
>  Is this behavior intended and if yes, why ? I would expect a compile error.
>
>
>
>  using System;
>
>  namespace ConsoleApplication1
>  {
>   class Program
>   {
>     static void Main(string[] args)
>     {
>       object value;
>       Parser.TryParse(typeof(int), "1", out value);
>
>       Console.ReadLine();
>     }
>   }
>
>   class Parser
>   {
>     public static bool TryParse<T>(string input, out T value)
>     {
>       Console.WriteLine("in Parse<T>, T='{0}'", typeof(T));
>
>       value = default(T);
>       return true;
>     }
>
>     public static bool TryParse(Type type, string input, out object value)
>     {
>       Console.WriteLine("in Parse, type='{0}'", type);
>
>       return TryParse(input, out value);
>     }
>   }
>  }
>
>  --
>  Sébastien
>  www.sebastienlorion.com
>
>  ===================================
>  This list is hosted by DevelopMentor(R)  http://www.develop.com
>
>  View archives and manage your subscription(s) at http://discuss.develop.com
>



-- 
Studying for the Turing test

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to