Generic class implementation??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hemantc87
    New Member
    • Mar 2010
    • 13

    Generic class implementation??

    i want to implement a sort function using a generic class.But when i declare the type generic parameter T it is not able to take the input from user.what should i do?

    Code:
     static void Sort<T>(ref T[] a)
            {
                
                T[] x;
               Console.Write("how many numbers u want to sort:);
                T q = Convert.ToInt32(Console.ReadLine());
    
                Console.WriteLine("enter the numbers you want to sort");
               
                int i = 0;
    
                for (i = 0; i < q; i++)
                {
                    Console.Write(" ");
                    x[i] = Console.ReadLine();
                }
                Array.Sort(a);
                Console.WriteLine(a);
    </code>

    T q = Convert.ToInt32 (Console.ReadLi ne())
    x[i] = Console.ReadLin e();
    both lines are giving errors??
    Last edited by tlhintoq; Mar 13 '10, 06:07 AM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      what should i do?
      You should go to the MSDN and look at Console.ReadLin e to see what the requirements are and determine if you are meeting them.

      For all those people who find it more convenient to bother you with their question rather than to Google it for themselves.

      Comment

      Working...