I got yelled at for trying to use the word question in the title so this is what I came up with. At any rate, this is a purely academic question about parameter types.
OK, so here is what I get.
using System;
namespace TypeParamTest
{
internal class Program
{
private static void Main(string[] args)
{
PrintType(1, new object());
Console.ReadKey();
}
static void PrintType<T, Ttwo>(T first, Ttwo second)
{
Console.WriteLine(typeof(T) + " : " + typeof(Ttwo));
}
}
}
That is clear and unambiguous to me (Astute readers will recognize this as a simple extension of an example found on page 249 of C# in Depth). I totally get what is happening, the compiler says there is some type (to be defined for T
and then for Ttwo
). What I don't understand is why on page 65 the example only has one type parameter.
List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> conv);
How does the compiler know about T
in this case?
We don't have enough information to answer for sure. Maybe T is defined on the surrounding class?
public class SomeClass<T> {
List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> conv);
}
If this is an example of List<T>
's ConvertAll method, then my suggestion above is the case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With