Sébastien Lorion <[EMAIL PROTECTED]> wrote:

> The following program outputs:
> 
> in Parse, type='System.Int32'

This is a run time type object you passed in explicitly.

> in Parse<T>, T='System.Object'

Here, T was inferred at compile time, not run time.

> Is this behavior intended and if yes, why ? I would expect a compile error.

It is expected behaviour for the given code. Whether it is intended
behaviour is a question you need to answer, since only you know the
provenance of this code.


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

3 arguments => Parser.TryParse(Type,string,out object)

>   class Parser
>   {
>     public static bool TryParse<T>(string input, out T value)

>     public static bool TryParse(Type type, string input, out object value)
>     {

>       return TryParse(input, out value);

You are calling TryParse with 2 arguments, => Parser.TryParse<T>(string,
outT) is the only candidate.

The first argument type is a string (input), the second argument type is
an object. Therefore, T is inferred to be of type System.Object (==
object).

-- Barry

-- 
http://barrkel.blogspot.com/

===================================
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