[RESOLVED] [2.0] Generic method issue..
I wrote some example code for practicing "generic methods". It went well when the method (which is a generic) had only one argument (generic collection class).
but when I pass 2 arguments for a method (generic), I get compile time error:
The type arguments for method 'ConsoleApplication1.Program.PrintVariableTypeLists<T>(System.Collections.Generic.List<T>, System.Collections.Generic.List<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
can some suggest me what is the problem in the way i am calling the generic method?
Code I wrote:
class Program
{
static void Main(string[] args)
{
List<int> aa = new List<int>();
aa.Add(1);
aa.Add(2);
aa.Add(3);
List<bool> bb = new List<bool>();
bb.Add(true);
bb.Add(false);
PrintVariableTypeLists(aa, bb);
}
static void PrintVariableTypeLists<T>(List<T> aa, List<T> bb)
{
foreach (T i in aa)
{
Console.WriteLine(i.ToString());
}
foreach (T j in bb)
{
Console.WriteLine(j.ToString());
}
}
}
Re: [2.0] Generic method issue..
Well you are trying to pass 2 different types to it. That's going to confuse the compiler.
Re: [2.0] Generic method issue..
PrintVariableTypeLists<A, B>(List<A> aa, List<B> bb)
Re: [2.0] Generic method issue..