accessor must be more restrictive than the property or indexer

后端 未结 2 1727
失恋的感觉
失恋的感觉 2020-12-14 15:39

I have the folowing class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;

namespace Framework         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 15:54

    Well, the error tells all the information required:

    accessibility modifier ... accessor must be more restrictive than the property ...

      private OdbcConnection db { // <- property as whole is "private"
        get; 
        private set; // <- accessor (set) is explictly declared as "private" 
      }
    

    So you can do either

      // property as a whole is "public", but "set" accessor is "private"
      // and so the accessor is more restrictive than the property
      public OdbcConnection db { // <- property as whole is "public"
        get; 
        private set; // <- accessor is "private" (more restrictive than "public")
      }
    

    Or

      private OdbcConnection db { 
        get; 
        set; // <- just don't declare accessor modifier
      }
    

提交回复
热议问题