Last active
September 24, 2015 20:45
-
-
Save hjerpbakk/36c0854b73d006cbdd9f to your computer and use it in GitHub Desktop.
Example of a C# struct
This file contains hidden or 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
public struct WidgetInformation : IEquatable<WidgetInformation> | |
{ | |
private readonly Guid id; | |
private readonly string name; | |
public WidgetInformation(Guid id, string name) | |
{ | |
this.id = id; | |
this.name = name; | |
} | |
public Guid Id { get { return id; } } | |
public string Name { get { return name; } } | |
public override bool Equals(object obj) | |
{ | |
return obj != null && obj.GetType() == GetType() && base.Equals((WidgetInformation)obj); | |
} | |
public bool Equals(WidgetInformation other) | |
{ | |
return id == null ? other.id == null : id.Equals(other.id); | |
} | |
public override int GetHashCode() | |
{ | |
return id == null ? base.GetHashCode() : id.GetHashCode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment