开发者

C# Value Type Class Template

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?

T开发者_运维百科hanks


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 !=.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜