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

  • Home
  • SEARCH
  • 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 3350298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:46:11+00:00 2026-05-18T01:46:11+00:00

I have a custom object ( DataPointCollection ) with two Integer properties and a

  • 0

I have a custom object (DataPointCollection) with two Integer properties and a Guid property. I want that object to generate a HashCode so that no two objects with the same values in those properties are added to a HashSet. I know I need to override the GetHashCode() method, but how do I do generate a hash code to accomplish this?

Here’s how I want to use it.

Dim dataPointCollections As New HashSet(Of DataPointCollection)()

For Each row As DataRow In myDataSet.Tables(0).Rows

  Dim dataPointCollection As New DataPointCollection()
  dataPointCollection.ProjectID = row("ProjectID") 'Integer'
  dataPointCollection.RoleID = row("RoleID") 'Integer'
  dataPointCollection.ResourceGUID = row("ResourceGUID") 'Guid'

  If Not dataPointCollections.Contains(dataPointCollection) Then
    dataPointCollections.Add(dataPointCollection)
  End If

Next

I’m open to other ideas, but I thought this might be faster than doing a LINQ query on a collection of objects (there could be a very large number of these objects).

  • 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-18T01:46:12+00:00Added an answer on May 18, 2026 at 1:46 am

    You need to override both GetHashCode and Equals – it’s the combination of the two which will be used by the HashSet.

    Your equality check should:

    • Check that the other object is of the same type as this object (it’s simpler if DataPointCollection is a sealed type; equality and inheritance are messy when combined)
    • Compare the three fields for equality

    Your hash code check needs to combine the three fields; the result doesn’t have to be unique; for performance it’s better if two unequal objects have a different hash code, but that’s not required. The absolute requirement is that two equal objects do have the same hash code. I’d do something like this (C#, but easy to convert to VB):

    public override int GetHashCode()
    {
        int hash = 17;
        hash = hash * 31 + projectId;
        hash = hash * 31 + roleId;
        hash = hash * 31 + resourceGuid.GetHashCode();
        return hash;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists of custom objects and want to update a field for
I have made a custom object called students that has two nsstring object. One
I have a custom object that contains an array (called children) where objects of
I have a custom object that implements INotifyPropertyChanged. I have a collection of these
I have a DateTime object that I need to print in a custom gridlike
I have a single NSDictionary object which contains a large number of custom objects.
I have a collection of custom entity objects one property of which is an
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have a custom object that maps a boolean value from a legacy database
I have a custom object that simply inherits from NSObject. It has 3 members

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.