tags:

views:

66

answers:

1

I'm writing/written a value type struct and was wondering if there was a guide that contains a standard template for method signatures and interface implementation. I thought I'd start by looking at the System.Double documentation:

struct def

public struct Double : IComparable, IFormattable, 
IConvertible, IComparable<double>, IEquatable<double>

Double Methods

Is there like a standard approach to creating a value type struct?

Thanks

+6  A: 

There isn't a template per se, but there are certainly guidelines. The most important guideline is value types should be immutable. Only violate this guideline if you know exactly what you are doing.

In addition to the guidelines listed in the MSDN article I linked to I also recommend:

  1. Override Object.Equals and Object.GetHashCode.
  2. Implement == and !=.
Jason
+1 Yah. What he said.
Joel Etherton
Thanks for the info.
john