Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Last active March 26, 2017 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmurphyscode/2d431c36b3d2f9e8affe9a8994cabde6 to your computer and use it in GitHub Desktop.
Save willmurphyscode/2d431c36b3d2f9e8affe9a8994cabde6 to your computer and use it in GitHub Desktop.
Simple demonstration that mutating an array in C# doesn't change its hash function, in contrast with Ruby.
using System;
using System.Collections.Generic;
namespace array_compare
{
class Program
{
static void DoesItChange()
{
Dictionary<int[], string> hash = new Dictionary<int[], string>();
int[] mutableArray = new int[] { 1,2 };
hash[mutableArray] = "foo";
Console.WriteLine(hash[mutableArray]); // prints "foo"
mutableArray[1] = 3;
Console.WriteLine(hash[mutableArray]); // prints "foo"
}
static void Main(string[] args)
{
DoesItChange();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment