Short answer, without knowing anything about the type, you can't do any form of sorting or advanced value checking, because it would make no sense. (What if someone made a YourTree<double>? Or a YourTree<Socket>? Then looking for the first few characters would be meaningless.)
The exceptions are things that work on Object, so you can:
- group them together by value equality using Object.Equals or EqualityComparer as Kim says
- use their hashcode, though this is generally not useful
- use their string representation (ToString()), which might be what you want
It sounds like you want to restrict your T to classes which have particular operations on them, namely, providing a name, and possibly be comparable. That means you need an interface, for example
public interface ITreeNode : IComparable<ITreeNode> {
string Name { get; }
}
... and then you need to restrict the T on your main class to support that interface:
public class MyBinaryTree<T> where T: ITreeNode {
...
}
Now, you can't create a MyBinaryTree<int> (int is not an ITreeNode), so you need to create ITreeNode subclasses for the data types you want to be in the tree. You can have a default one that looks like
public class TreeNode<T> : ITreeNode {
T inner;
public TreeNode(T inner) { this.inner = inner; }
public int CompareTo(T other){
if(inner is IComparable<T>) return ((IComparable<T>)inner).CompareTo(IComparable<T>)other);
else return StringComparer.CurrentCulture.Compare(inner, other);
}
public string Name { get { return inner.Name; } }
}
... which wraps any type and uses its comparer if it has one, otherwise the string representation. (I think the native numeric types support IComparable<T> so they should sort correctly.) Now you can do
var myTree = new MyBinaryTree<TreeNode<int>>();
.. and within MyBinaryTree, you can use the methods of ITreeNode (i.e. the name), and also treat the nodes as IComparable<T> (i.e. pass them to sorting routines).
Hopefully that gives you enough information that you can work out exactly how to apply it to your situation.
E: Naturally, this was made up on the spot, not tested, and probably won't even compile. Also, generic types and HTML don't really play well together.