I am trying to create a generic node class that can contain any number of child nodes, a string for the node key and node data, which may or may not be null. However, I am having trouble getting the syntax of the right to accept a generic value as a generic parameter for Nullable.
internal class TrieNode<E>
{
Nullable<E> Data;
string Key;
List<TrieNode<E>> Children;
public TrieNode(E? data, string key)
{
Data = data;
Key = key;
Children = new List<TrieNode<E>>();
}
}
At compile time, I get the following error message:
Type "E" must be an unimaginable value type in order to use it as the "T" parameter in a generic type or "System.Nullable" method
Is there a way to guarantee that E is a type that does not contain NULL, or in any other way?
source
share