C# getter vs readonly

前端 未结 9 2169
遥遥无期
遥遥无期 2020-12-29 19:23

Is there any difference between the following?

class C
{
    // One:
    public static readonly int ValueAsAMember = 42;

    // Two:
    public static int V         


        
9条回答
  •  [愿得一人]
    2020-12-29 20:06

    I think the first line making something constant or rather readonly using readonly keyword.

    and the second line is making use of a property to implement readonly. Both do the same but if you compare with the IL the property would add few extra lines of code to the dll.

提交回复
热议问题