开发者

C# Value Type Class Template

开发者 https://www.devze.com 2022-12-16 16:28 出处:网络
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

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

精彩评论

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