Using strongly typed IComparable with SortedDictionary

I started out with a SortedDictionary of objects which implement an IComparable interface.  The code looked like this:

private void button1_Click(object sender, EventArgs e) {
cStudent Bobby = new cStudent("Bobby Smith");
cStudent Dana = new cStudent("Dana Mulberry");
cStudent Karl = new cStudent("Karl Burrows");

SortedDictionary<ObjectIComparable, string> stuDic = new SortedDictionary<ObjectIComparable, string>();
stuDic.Add(new ObjectIComparable(Bobby), Bobby._name);
stuDic.Add(new ObjectIComparable(Dana), Dana._name);
stuDic.Add(new ObjectIComparable(Karl), Karl._name);
}

public class cStudent {
      public string _name;
      public cStudent(string pName) {
            _name = pName;
      }
}
public class ObjectIComparable : IComparable {
      public cStudent _student;
      public ObjectIComparable(cStudent pStu) {
            _student = pStu;
      }
      #region IComparable Members

      public int CompareTo(object obj) {
            ObjectIComparable other = (ObjectIComparable)obj;
            return String.Compare(other._student._name, _student._name);
      }

      #endregion
}

This worked fine, all three objects were added into the dictionary.  Then I wanted to make the IComparable object more strongly typed, something like this:

public class StudentIComparable : IComparable<cStudent> {
      public cStudent _student;
      public StudentIComparable(cStudent pStu) {
            _student = pStu;
      }
      #region IComparable<cStudent> Members

      int IComparable<cStudent>.CompareTo(cStudent other) {
            return String.Compare(other._name, _student._name);
      }

      #endregion
}

...but when I tried to create the dictionary

SortedDictionary<StudentIComparable, string> stuDic2 = new SortedDictionary<StudentIComparable, string>();
stuDic2.Add(new StudentIComparable(Bobby), Bobby._name);
stuDic2.Add(new StudentIComparable(Dana), Dana._name);
stuDic2.Add(new StudentIComparable(Karl), Karl._name);

...it compiled just fine but when I ran it, the second "Add" threw this error:
"At least one object must implement IComparable"

There must be some mistake that I have made with my syntax, can anyone tell me how to fix it?

Just to clarify the intent of my question: yes, I know there are easier and more efficient ways of accomplishing this task, I just want to get it working as an educational exercise.
LVL 1
FrancineTaylorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tikusbalapCommented:
I think you should implement IComparable to StudentIComparable as well.

public class StudentIComparable : IComparable, IComparable<cStudent>
{
      public cStudent _student;
      public StudentIComparable(cStudent pStu) {
            _student = pStu;
      }
      #region IComparable<cStudent> Members

      int IComparable<cStudent>.CompareTo(cStudent other) {
            return String.Compare(other._name, _student._name);
      }

      public int CompareTo(object obj) {
            ObjectIComparable other = (ObjectIComparable)obj;
            return String.Compare(other._student._name, _student._name);
      }

      #endregion
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FrancineTaylorAuthor Commented:
Bingo!  Thanks, tikusbalap, that worked.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.