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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:46:43+00:00 2026-05-16T05:46:43+00:00

I have implemented some version of tuple class , and really want to learn

  • 0

I have implemented some version of tuple class , and really want to learn more from it .

Can you please point me on some points that I am missing here with my implementation.

class My_tuple<T1, T2> : EqualityComparer<My_tuple<T1, T2>>
    {

#region Virables
        public T1 First { get; private set; }

        public T2 Second { get; private set; }
#endregion

#region Constractors

        public My_tuple(T1 first, T2 second)
        {
            First = first;
            Second = second;
        }

#endregion

#region Equals && GetHashCode

        public override bool Equals(My_tuple<T1, T2> L, My_tuple<T1, T2> R)
        {
            return EqualityComparer<T1>.Default.Equals(L.First, R.First) && EqualityComparer<T2>.Default.Equals(L.Second , R.Second);
        }

        public override bool Equals(object obj)
        {
            return obj is My_tuple<T1, T2> && Equals(this, (My_tuple<T1, T2>)obj); 
        }

        public override int GetHashCode(My_tuple<T1, T2> M)
        {
            return M.First.GetHashCode() ^ M.Second.GetHashCode();
        }

#endregion

#region operators

        public static bool operator ==(My_tuple<T1, T2> left, My_tuple<T1, T2> right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(My_tuple<T1, T2> left, My_tuple<T1, T2> right)
        {
            return !(left == right);
        }

        public static My_tuple<T1, T2> Create<T1, T2>(T1 first, T2 second)
        {
            return new My_tuple<T1, T2>(first, second);
        }

#endregion

    }

Thanks.

  • 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-16T05:46:44+00:00Added an answer on May 16, 2026 at 5:46 am

    A few things:

    • The type name doesn’t comply with .NET conventions
    • Various parameter names don’t comply with .NET conventions
    • You shouldn’t derive from EqualityComparer<T> – you should implement IEqualityComparer<T>.
    • Your implementation of GetHashCode() is non-ideal; it means that for any tuple with the same type of left and right (e.g. My_tuple<int, int>) where the values are equal, you’ll get the same hash code of 0. i.e. (1, 1) has the same hash code as (2, 2) etc. I prefer an “add and multiply” implementation – in this case you could return (say) 17 * hash1 + 31 * hash2. There will still be collisions, but hopefully not as many.
    • Your implementation of Equals(L, R) assumes that L and R are non-null
    • Your Create method is generic, attempting to redeclare the T1 and T2 type parameters. I’m surprised that even compiles, although it’s something I haven’t tried before. Consider creating a static generic method in a non-generic class (e.g. just My_tuple) to allow type inference to work, e.g. My_tuple.Create(1, "hello") to create a My_tuple<int, string>
    • I would personally use private readonly fields and simple property getters, rather than automatic properties. It’s not immediately obvious from the declaration that you’ll never change the values of the properties – you have to read all of the code.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Upgrade PHP from version 5.2 to 5.3 I have 15 sites implemented
I have already implemented some AJAX pagination in my Rails app by using the
I have implemented PullRefreshTableViewController with some classes that take no delegates, and it works
I have some classes as below, i have implemented the Equals(Object) method for almost
I have implemented an application for modify the xml layout with some properties. I
I have implemented Shake Event listener in my application and onShake do some logic.
I have implemented a simple linux shell in c. Now, I am adding some
I have some 5 XML calls to be implemented in C#. I used Xsd2Code
I have some REST web services implemented in WCF. I wish to make these
I wants to have some knowledge about how database management software is implemented. Is

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.