public class MyEvent { public string Name { get; set; } public int Id { get; set; } public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + Name.GetHashCode(); hash = hash * 23 + Id.GetHashCode(); return hash; } } }
var eventType1 = typeof(MyEvent); var eventType2 = typeof(OtherEvent); if (eventType1.GetHashCode() == eventType2.GetHashCode()) { // Event types are equal } else { // Event types are not equal }In this example, the hash codes for two different event types are compared. If the hash codes are equal, it means that the event types are the same. This can be useful when comparing event types in a switch statement or when looking up event types in a dictionary. Package library: This method is a part of the System.Type class, which is included in the core .NET Framework library.