【问题标题】:The accessibility of the 'GetServiceCafe.EntityCafe.hasil.get' accessor must be more restrictive than the property or indexer?'GetServiceCafe.EntityCafe.hasil.get' 访问器的可访问性必须比属性或索引器更具限制性?
【发布时间】:2016-06-08 17:22:28
【问题描述】:

我的问题是当我尝试调试我的程序时出现错误“属性或索引器 'GetServiceCafe.EntityCafe.hasil' 无法在此上下文中使用,因为 get 访问器无法访问”

我正在尝试使用此 accessor must be more restrictive than the property or indexer 修复它,但在我的情况下,主要问题是 get 未设置,我尝试将 get 更改为公开但仍然出现此错误。

EntityCafe.cs:

namespace GetServiceCafe
{
    class EntityCafe
    {
        List<EntityData> hasil { get; set; }
    }

    public class EntityData
    {
        public int ID_Transaksi { get; set; }
        public string Nama_Pemesan { get; set; }
        public int Status { get; set; }
        public string Detail_Pesanan { get; set; }
        public int Total_Biaya { get; set; }
        public string Jenis_Transaksi { get; set; }
        public string Cabang { get; set; }
    }
}

Form1.cs:

DataTable table = new DataTable("myTable");
table.Columns.Add("ID_Transaksi", typeof(string));
table.Columns.Add("Nama Pemesan", typeof(string));
table.Columns.Add("Detail Pesanan", typeof(string));
table.Columns.Add("Total_Biaya", typeof(string));
table.Columns.Add("Jenis_Transaksi", typeof(string));
table.Columns.Add("Cabang", typeof(string));

foreach (var obj in dataPengiriman.hasil)
{
    DataRow row = table.NewRow();//empty row
    row[0] = obj.id_transaksi.ToString();
    row[1] = obj.nama_pemesan.ToString();
    row[2] = obj.detail_pesanan.ToString();
    row[3] = obj.total_biaya.ToString();
    row[4] = obj.jenis_transaksi.ToString();
    row[5] = obj.cabang.ToString();
    table.Rows.Add(row);
}

【问题讨论】:

    标签: c# visual-studio-2012


    【解决方案1】:

    该列表无法访问,因为它不是public,您可以获取public

    public class EntityCafe 
    {
        public List<EntityData> hasil { get; private set; } // it should be Hasil 
    }
    

    请注意,如果您想从表单创建实例,该类也必须是 public

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      • 2011-12-10
      • 2016-05-09
      • 1970-01-01
      • 2015-05-08
      • 1970-01-01
      相关资源
      最近更新 更多