add unique Elements to List of User defined class (i.e. List )
public class Operand: IEnumerable, IEnumerator
{
public String opr;
public String state;
}
i want made it and implement all necessary routines to apply List on it.
(Note : class Operand: IEnumerable, IEnumerator )
but when i am Trying to add elements ie Operand ‘s object
operand tem1=new Operand(“eax”,”undef”);
operand tem2=new Operand("ebx","undef");
operand tem3=new Operand("ecx","undef");
operand tem4=new Operand("eax","undef");
operand tem5=new Operand("eax","undef");
then i want to add these 5 temp[1-5] elements in List OR HashSet.
and if there is duplicate element the update the state of that element to Def i.e.Define
how do i do it…
please help me..
In your
Operandclass override theGetHashCodeMethodandEqualsmethod. Make sure you return a unique HashCode for uniqueOperandinstance and also make sure if two operands are same i.e. their property values are same return true in equals method and false otherwiseAfter implementing these method you can check for duplicate in the
ListofHashsetby usingContainsmethod. If you find the duplicate instead of inserting new record update the existing one.