static readonly field initializer vs static constructor initialization

前端 未结 4 983
别跟我提以往
别跟我提以往 2020-12-02 13:16

Below are two different ways to initialize static readonly fields. Is there a difference between the two approaches? If yes, when should one be preferred over the other?

4条回答
  •  心在旅途
    2020-12-02 13:56

    They are essentially the same, but if you happen to have both a read-only assignment to a static field and a static type constructor, the read-only assignment occurs first.

提交回复
热议问题