c#.NET interface question
Hi, I'm trying to learn a bit of c#.NET for a job placement that I've got over the summer and I was wondering if someone could clarify something for me.
I was attempting to implement a binary search tree - or rather have implemented it, since it works - (for practice as much as anything else) and I ran into a bit of trouble with the use of interfaces. Before going on I'll paste in the code for my BSTNode:
Code:
public interface IBSTNode
{
Comparable Data
{
get;
set;
}
IBSTNode Right
{
get;
set;
}
IBSTNode Left
{
get;
set;
}
}
The problem that I'm getting is that when I attempt to implement the code, because I've set the types of left and right to IBSTNode I either have to then declare every use of BSTNodes as IBSTNode or I have to typecast, eg:
Code:
IBSTNode tmpNode = aNode;
tmpNode = tmpNode.Right;
or
BSTNode tmpNode = aNode;
tmpNode = (BSTNode)tmpNode.Right;
If anyone understands what I'm talking about and can give me a way round it that would be great - just please bear in mind that I've had about two days experience at c# or so :P
ac