Declaring strings public static readonly versus public const versus public static const

后端 未结 5 1618
故里飘歌
故里飘歌 2021-02-01 02:47

In each project we have there is a file used to store the various SQL statements used in that project. There are a handful of variations on how the class is declared and how the

5条回答
  •  悲&欢浪女
    2021-02-01 03:21

    Given that you're using Visual Studio, a small benefit for using public const over public static readonly is the ability to use IntelliSense to "peak" at the const value.

    e.g. Given:

    public class Constants
    {
         public const string ConstString = "Visible!";
         public static readonly string StaticReadonlyString = "Invisible!";
    }
    

    hovering over a string that's a constant hovering over a string variable that's static readonly

提交回复
热议问题