Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:29:20+00:00 2026-05-28T14:29:20+00:00

add unique Elements to List of User defined class (i.e. List ) public class

  • 0

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..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:29:21+00:00Added an answer on May 28, 2026 at 2:29 pm

    In your Operand class override the GetHashCodeMethod and Equals method. Make sure you return a unique HashCode for unique Operand instance and also make sure if two operands are same i.e. their property values are same return true in equals method and false otherwise

    public override bool Equals(object obj)
            {
                if(obj is Operand)
                {
                    Operand op = obj as Operand;
                    if (this.opr == op.opr && this.state == op.state)
                        return true;
                }
                return false;
            }
    
      public override int GetHashCode()
        {
            int hash = 13;
            hash = (hash * 7) + opr.GetHashCode();
            hash = (hash * 7) + state.GetHashCode();
            return hash;
        }
    

    After implementing these method you can check for duplicate in the List of Hashset by using Contains method. If you find the duplicate instead of inserting new record update the existing one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class like this: public class myClass { public List<myOtherClass> anewlist =
I have a situation where I need to add an arbitrary unique id to
To add a whitespace seperator in a string we use String.Join(). My question:What(and how)
I add this class to library/My/Validate/PasswordConfirmation.php <?php require_once 'Zend/Validate/Abstract.php'; class My_Validate_PasswordConfirmation extends Zend_Validate_Abstract {
Take List<Car> . Each Car has a unique index identifying it, say RegNumber and
Him I'm trying to add a jQuery tooltip to a dynamically generated list, the
I have a 100 classes that have some similar elements and some unique. I've
I know the differences between Set and List(unique vs. duplications allowed, not ordered/ordered, etc).
I know the differences between Set and List(unique vs. duplications allowed, not ordered/ordered, etc).
I have a list of about a hundreds unique strings in C++, I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.