Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Nice idea though I suspect that this might have issues with GC churn since you are implicitly creating a short lived object Commented Nov 27, 2017 at 10:50
  • 13
    @RobV Tuples are value types, so they are stack allocated and exert no GC pressure. Commented Feb 13, 2018 at 10:34
  • 4
    One problem... (0,1,2).GetHashCode() and (0,0,1,2).GetHashCode() both yield the same value: 35. Whereas the method in the most upvoted answer yields unique values 0, 1, 2: 506480 and 0, 0, 1, 2: 15699890 Commented Jun 17, 2018 at 22:23
  • 2
    Hashcodes aren't guaranteed to be unique. You found a case where it isn't... It doesn't make it a bad choice unless there are a lot of collisions(in that case it would be a good idea to submit a bug). I personally prefer to use something from the framework instead of implementing something different. Commented Jun 24, 2018 at 15:08
  • 3
    It's actually ValueTuple type of a struct (MSDN). Be careful that Tuple type is a class and it has GC pressure. I like this way. Internally it's similar to @Stipo 's post but very easy to understand and to review. It would be good choice in most cases. Commented Aug 16, 2018 at 10:05