473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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?

Expand|Select|Wrap|Line Numbers
  1.  static void Sort<T>(ref T[] a)
  2.         {
  3.  
  4.             T[] x;
  5.            Console.Write("how many numbers u want to sort:);
  6.             T q = Convert.ToInt32(Console.ReadLine());
  7.  
  8.             Console.WriteLine("enter the numbers you want to sort");
  9.  
  10.             int i = 0;
  11.  
  12.             for (i = 0; i < q; i++)
  13.             {
  14.                 Console.Write(" ");
  15.                 x[i] = Console.ReadLine();
  16.             }
  17.             Array.Sort(a);
  18.             Console.WriteLine(a);
</code>

T q = Convert.ToInt32(Console.ReadLine())
x[i] = Console.ReadLine();
both lines are giving errors??
Mar 13 '10 #1
2 1767
tlhintoq
3,525 Expert 2GB
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.
Mar 13 '10 #2
tlhintoq
3,525 Expert 2GB
what should i do?
You should go to the MSDN and look at Console.ReadLine to see what the requirements are and determine if you are meeting them.

http://www.lmgtfy.com/?q=MSDN+Consol...UTF-8&oe=UTF-8
Mar 13 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steven Bethard | last post by:
So I'm trying to get a prototype implementation of the 'generic object' type. (I'm currently calling it 'bunch', but only because I can't really think of anything better.) I'd like some feedback...
49
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another...
3
by: SimonH | last post by:
Hi all, I would like to make a generic set of methods that could be called regardless of the database behind the scenes. One of the methods I would like would take a string sql statement and...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
10
by: steve bull | last post by:
I have a class SwatchPanel which takes Swatch as a parameter type. How can I call a static function within the Swatch class? For example the code below fails on TSwatch.Exists. How can I get the...
9
by: mps | last post by:
I want to define a class that has a generic parameter that is itself a generic class. For example, if I have a generic IQueue<Tinterface, and class A wants to make use of a generic class that...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
6
by: =?Utf-8?B?RG9uYWxkIFhpZQ==?= | last post by:
In C# 2, this works just fine: public class foo : IEnumerable<string> { private string _list; public IEnumerator<stringGetEnumerator() { foreach (string s in _list) yield return s; }
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.