Pattern for Creating a Simple and Efficient Value type

前端 未结 4 1861
臣服心动
臣服心动 2020-12-24 12:34

Motivation:

In reading Mark Seemann’s blog on Code Smell: Automatic Property he says near the end:

The bottom line is that au

4条回答
  •  一生所求
    2020-12-24 13:27

    I think this is a perfectly fine implementation pattern for value types. I've done similar things in the past that have worked out well.

    Just one thing, since Celsius is implicitly convertible to/from int anyway, you can define the bounds like this:

    public const int MinValue = -273;
    public const int MaxValue = int.MaxValue;
    

    However, in reality there's no practical difference between static readonly and const.

提交回复
热议问题