473,231 Members | 1,847 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,231 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 1256
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,...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.