|
-
Aug 16th, 2006, 12:26 PM
#1
Thread Starter
Hyperactive Member
[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());
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|