Why Automatically implemented properties must define both get and set accessors

前端 未结 3 1819
-上瘾入骨i
-上瘾入骨i 2020-12-15 03:12

When we define a property like

    public string Name {get; set;}

dot net can make our properties code. but when we use

            


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 04:13

    A more modern scenario for receiving this error is building code that uses C#6 syntax using a version of VisualStudio that is less than VS 2015 (or using MsBuild that is less than 14).

    In C#6.0 it is allowable to have autoProperties that do not have a setter (they are assumed to be a private set).

    Try compiling with VS2015+ or msbuild 14+ .. or modify the code so that all autoProperties have a setter.

提交回复
热议问题