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 6326357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:04:27+00:00 2026-05-24T17:04:27+00:00

This is a project question that i just cant seem to answer using System;

  • 0

This is a project question that i just cant seem to answer

using System;

namespace ConsoleApplication2
{
    internal class Equipment : IComparable
    {
        private readonly string type;
        private readonly int serialNo;
        private string colour;
        public decimal cost;

        public Equipment(string type, int serialNo)
        {
            this.type = type == null ? "" : type.Trim();
            this.serialNo = serialNo;
        }

        public string Key
        {
            get { return type + ":" + serialNo; }
        }

        int IComparable.CompareTo(object obj)
        {
            return 0;
        }
    }
}

(a) Override the appropriate method o ensure that different instances of the class that represent the same equipment item will be considered the same in the system.

(b) Override the appropriate method to enable instances of this class to be stored (and found) by key in a hash table

  • 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-24T17:04:27+00:00Added an answer on May 24, 2026 at 5:04 pm

    Writing GetHashCode manually is not that easy. Anyhow, that’s code generated for this purpose by ReSharper. It’s a complete solution. (It should be contained within your class definition of course). But what would you say, if you were asked – why and how it works? It might be embarassing.

    So, apart from GetHashCode and Equals, which others have suggested you reading about, you might also look up http://msdn.microsoft.com/en-us/library/system.object.referenceequals.aspx as well as http://msdn.microsoft.com/en-us/library/a569z7k8(v=VS.100).aspx

    As for the mystery behind 397 in GetHashCode, have a look at this question here on StackOverflow: Why is '397' used for ReSharper GetHashCode override?

            public bool Equals(Equipment other)
            {
                if (ReferenceEquals(null, other))
                {
                    return false;
                }
                if (ReferenceEquals(this, other))
                {
                    return true;
                }
                return Equals(other.colour, colour) && other.cost == cost && other.serialNo == serialNo && Equals(other.type, type);
            }
    
            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj))
                {
                    return false;
                }
                if (ReferenceEquals(this, obj))
                {
                    return true;
                }
                if (obj.GetType() != typeof (Equipment))
                {
                    return false;
                }
                return Equals((Equipment) obj);
            }
    
    // note: if "Override the appropriate method to enable instances of this class
    // to be stored (and found) by key in a hash table" is supposed to mean that only type and
    // serialNo should be taken into account (since they are used to generate
    // the Key value) - just remove the lines with cost and colour
            public override int GetHashCode()
            {
                unchecked
                {
                    int result = (colour != null ? colour.GetHashCode() : 0);
                    result = (result*397) ^ cost.GetHashCode();
                    result = (result*397) ^ serialNo;
                    result = (result*397) ^ (type != null ? type.GetHashCode() : 0);
                    return result;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a two-part question. I'm using jQuery for a project and wanting to
I really need an answer to this question. I am working on a project
There is another recent Project Euler question but I think this is a bit
This is a question about tidyness. The project is already working, I'm satisfied with
I ask this question in anticipation as part of a project. I have experience
This has got to be a lamer question: In my test project I am
This is mostly a data warehouse philosophy question. My project involves an Oracle forms
Consider the scenario of upgrading an ASP.NET MVC project. This question is around up-converting
All, I'm working on a SharePoint project, but this isn't a SharePoint-specific question per-se.
I have looked for an answer for this nearly every where that I can

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.