Click here to Skip to main content
15,396,210 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I Overrided Equal(Object obj) in a Class for example Student class for removing an item from a list box when I entered the name and family of a student in textBoxes after that my Add method didn't work. why it happened?

C#
Student s = new student();
s.name=TextBox1.text;
s.family=TextBox2.text;
Lst1.Items.Add(s);

above code didn't work when I overrided Equals(Object obj) For removing items from listBox.

C#
Lst1.Items.Remove(s);
Posted
Updated 4-Jan-12 4:21am
v3
Comments
Richard MacCutchan 4-Jan-12 10:22am
   
What does "didn't work" mean?
Mike Hankey 4-Jan-12 10:26am
   
You also need to add the overridden Equals code.
   
Please make a (minimalistic) code sample showing all the relevant code and manifests the problem.
--SA
fjdiewornncalwe 4-Jan-12 15:05pm
   
Could you show the Equals override, please. If your change to that caused the problem, then we need to see it in order to help you.
GParkings 14-Feb-12 7:15am
   
did you also override the GetHashCode method?, you should have, .. post that code up as well

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900