473,396 Members | 2,018 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,396 software developers and data experts.

Referencing a Generic

PJ
I have a class defined as so:

public class Pager : Control
{
private PagingList<T> itemList;
....

I'm getting an error message that says, "The type or namespace name 'T'
could not be found. Obviously, I'm just trying to define a class that
PagingList is a class that compiles just fine that inherits from List<T>.

What gives? thx,

~PJ


Jan 14 '06 #1
5 1264
PJ
ok, so apparently i can do:

private PagingList<object> itemList;

which works for my implementation, as I am only concerned w/ the methods of
the subclass PagingList<T> which inherits from List<T>, but I still do not
understand why I cannot use a generic in this situation?

~PJ

"PJ" <pj***@hotmail.com> wrote in message
news:q4********************@speakeasy.net...
I have a class defined as so:

public class Pager : Control
{
private PagingList<T> itemList;
...

I'm getting an error message that says, "The type or namespace name 'T'
could not be found. Obviously, I'm just trying to define a class that
PagingList is a class that compiles just fine that inherits from List<T>.

What gives? thx,

~PJ

Jan 14 '06 #2
PJ <pj***@hotmail.com> wrote:
I have a class defined as so:

public class Pager : Control
{
private PagingList<T> itemList;
...

I'm getting an error message that says, "The type or namespace name 'T'
could not be found. Obviously, I'm just trying to define a class that
PagingList is a class that compiles just fine that inherits from List<T>.

What gives? thx,


You need to make your Pager a generic class as well - otherwise it
doeesn't know what T is:

public class Pager<T> : Control
{
....
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 14 '06 #3
I think all that you are missing is a <T> on the Pager - i.e. if this was
public class Pager<T> : Control you would have a type-safe pager, and
itemList would automatically adopt the same T as the T used in Pager. Note,
however, that generic controls don't work very well in the designer; you
will probably need to add them to forms programatically.

The whole point of generics is to provide a re-usable, type-safe construct.

In your example, what objects would the PagingList contain? i.e. what would
it's Add method look like? If you want it accept any type of object, then
that would (as you have found) by PagingList<object>, and it will be
Add(object obj) - however, the main point of generics is that I might want a
strongly typed list of MachinePart objects - i.e. it will accept only
MachinePart objects and subclasses - this would be PagingList<MachinePart>,
and would have Add(MachinePart obj) and the indexer would be "MachinePart
this[int index]" etc.

Does that help?

"PJ" <pj***@hotmail.com> wrote in message
news:tq******************************@speakeasy.ne t...
ok, so apparently i can do:

private PagingList<object> itemList;

which works for my implementation, as I am only concerned w/ the methods
of the subclass PagingList<T> which inherits from List<T>, but I still do
not understand why I cannot use a generic in this situation?

~PJ

"PJ" <pj***@hotmail.com> wrote in message
news:q4********************@speakeasy.net...
I have a class defined as so:

public class Pager : Control
{
private PagingList<T> itemList;
...

I'm getting an error message that says, "The type or namespace name 'T'
could not be found. Obviously, I'm just trying to define a class that
PagingList is a class that compiles just fine that inherits from List<T>.

What gives? thx,

~PJ


Jan 14 '06 #4
PJ wrote:
I have a class defined as so:

public class Pager : Control
{
private PagingList<T> itemList;
....

I'm getting an error message that says, "The type or namespace name 'T'
could not be found. Obviously, I'm just trying to define a class that
PagingList is a class that compiles just fine that inherits from List<T>.

What gives? thx,

~PJ


It is impossible to define a class that inherits from a generic class
like that. In your example I would say it would be impossible because
the code would need to know what kind of type it is actually dealing with.

However, I've also seen needs for defining a method that takes a List<T>
argument and not be generic itself, and this is also impossible.

In other words, if you want the above code to compile, make Pager a
generic class as well, otherwise you're going to need to find a
different solution. For instance, you could use IList or similar without
using it as a generic interface.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Jan 14 '06 #5
Lasse Vågsæther Karlsen wrote:
PJ wrote:
I have a class defined as so:

public class Pager : Control
{
private PagingList<T> itemList;
....
<snip> It is impossible to define a class that inherits from a generic class
Ok, this should say "variable".
like that. In your example I would say it would be impossible because
the code would need to know what kind of type it is actually dealing with.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Jan 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: student | last post by:
while compiling on: SunOS 5.8 Generic_108528-27 sun4u sparc SUNW,Sun-Fire-280R I get the following error: Undefined first referenced symbol ...
1
by: jesse.hartwick | last post by:
Hey.. I was just wondering why there are so many ways to reference a form and what are the pros and cons of using each. I've seen at least 5 different ways, which is correct (or in what...
16
by: PromisedOyster | last post by:
Hi I have a situation where I want to use circular referencing. I have cut down the example for demonstration purposes. Say we have one executable (main.exe) and two DLLS (A1.dll and A2.dll)....
9
by: Brett Romero | last post by:
Say I have a library (A.dll) with a method that accepts a collection of a specific type. The type is defined in B.dll. In A.dll, I need to loop through this collection and reference fields of...
4
by: Mantorok | last post by:
Hi Is it possible to reference controls or pages in a seperate ASP.Net website project? Thanks
1
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
2
by: Andrus | last post by:
I need compile in-memory assembly which references to other in-memory assembly. Compiling second assembly fails with error Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0, Culture=neutral,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.