Last active
March 26, 2017 22:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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