Skip to content

Instantly share code, notes, and snippets.

@hjerpbakk
Last active September 24, 2015 20:45
Show Gist options
  • Save hjerpbakk/36c0854b73d006cbdd9f to your computer and use it in GitHub Desktop.
Save hjerpbakk/36c0854b73d006cbdd9f to your computer and use it in GitHub Desktop.
Example of a C# struct
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