Created
October 16, 2020 14:07
-
-
Save kekyo/6001dd5238dd381606df7916faf4fe07 to your computer and use it in GitHub Desktop.
ValueTypeHashCodeTest.cs
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; | |
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