You can implement a general comparator:
public class MyStructComparer : IEqualityComparer<MyStruct> { public bool Equals(MyStruct x, MyStruct y) {
Then use this for the constructor of the word:
var myStructDict = new Dictionary<MyStruct, string>(new MyStructComparer());
Another way is to implement IEquatable<MyStruct> in MyStruct , for example:
public struct MyStruct: IEquatable<MyStruct> { public int Id; public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; return obj is MyStruct && Equals((MyStruct)obj); } public bool Equals(MyStruct other) { return this.Id == other.Id; } public override int GetHashCode() { return this.Id; } }
Then the dictionary can be initialized by the default constructor:
var myStructDict = new Dictionary<MyStruct, string>();
source share