Why does C# not allow const and static on the same line?

前端 未结 5 709
一个人的身影
一个人的身影 2021-02-02 10:03

Why does C# not allow const and static on the same line? In Java, you must declare a field as \'static\' and \'final\' to act as a constant. Why does C# not let you declare co

5条回答
  •  深忆病人
    2021-02-02 10:49

    Because allowing and not requiring modifiers that are inherent can cause confusion. If you see

    static const int A = 3
    const int B = 5
    

    you may believe that they are 2 different kinds of constants.
    Even VB 2008 (which can be very verbose if you wish) doesn't allow that.

提交回复
热议问题