using System.Collections.Generic;
public sealed class LoLQueue<T> where T: class
{
private SingleLinkNode<T> mHe;
private SingleLinkNode<T> mTa;
public LoLQueue()
{
this.mHe = new SingleLinkNode<T>();
this.mTa = this.mHe;
}
}
Error:
The non-generic type 'LoLQueue<T>.SingleLinkNode' cannot be used with type arguments
Why do i get this?
If you want to use IEnumerable<T>
, as your post's title suggests, you need to include using System.Collections.Generic;
.
As for the SingleLinkNode class, I don't know where you got it, it's not part of the .NET framework that I can see. I'd guess that it isn't implemented using generics, and you'll need to add a bunch of casts from object
to T
everywhere.
I'm pretty sure you haven't defined your SingleLinkNode
class as having a generic type parameter. As such, an attempt to declare it with one is failing.
The error message suggests that SingleLinkNode
is a nested class, so I suspect what may be happening is that you are declaring members of SingleLinkNode
of type T
, without actually declaring T
as a generic parameter for SingleLinkNode
. You still need to do this if you want SingleLinkNode
to be generic, but if not, then you can simply use the class as SingleLinkNode
rather than SingleLinkNode<T>
.
Example of what I mean:
public class Generic<T> where T : class
{
private class Node
{
public T data; // T will be of the type use to construct Generic<T>
}
private Node myNode; // No need for Node<T>
}
If you do want your nested class to be generic, then this will work:
public class Generic<T> where T : class
{
private class Node<U>
{
public U data; // U can be anything
}
private Node<T> myNode; // U will be of type T
}
This compiles for me:
public sealed class SingleLinkNode<T>
{
}
public sealed class LoLQueue<T> where T : class
{
private SingleLinkNode<T> mHe;
private SingleLinkNode<T> mTa;
public LoLQueue()
{
this.mHe = new SingleLinkNode<T>();
this.mTa = this.mHe;
}
}
You'll need to post your SingleLinkNode class for further answers...
John
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With