Skip to content

Instantly share code, notes, and snippets.

@kekyo
Created October 16, 2020 14:07
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 kekyo/6001dd5238dd381606df7916faf4fe07 to your computer and use it in GitHub Desktop.
Save kekyo/6001dd5238dd381606df7916faf4fe07 to your computer and use it in GitHub Desktop.
ValueTypeHashCodeTest.cs
using System;
namespace ConsoleApp1
{
//.class private sealed sequential ansi beforefieldinit
//ConsoleApp1.Test
//extends [System.Runtime]System.ValueType
//{
// .field public int32 IntValue
// .field public string StringValue
//} // end of class ConsoleApp1.Test
struct Test
{
public int IntValue;
public string StringValue;
}
class Program
{
static void Main(string[] args)
{
var test1 = new Test {IntValue = 123, StringValue = "ABC"};
var test2 = new Test {IntValue = 123, StringValue = "ABC"};
var test3 = new Test {IntValue = 456, StringValue = "ABC"};
Console.WriteLine($"test1: {test1.GetHashCode()}");
Console.WriteLine($"test2: {test2.GetHashCode()}");
Console.WriteLine($"test3: {test3.GetHashCode()}");
// test1: -1101417565
// test2: -1101417565
// test3: -1101417968
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment