Results 1 to 4 of 4

Thread: [RESOLVED] [2.0] Generic method issue..

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Resolved [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());
    }


    }




    }

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Generic method issue..

    Well you are trying to pass 2 different types to it. That's going to confuse the compiler.
    I don't live here any more.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] Generic method issue..

    PrintVariableTypeLists<A, B>(List<A> aa, List<B> bb)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: [2.0] Generic method issue..

    thanks.

    it works now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width