2016-06-08 47 views
0

我的問題是,當我嘗試調試我的程序,我得到錯誤「屬性或索引‘GetServiceCafe.EntityCafe.hasil’不能在這種情況下,因爲get訪問無法訪問使用」'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); 
} 

回答

0

列表是不可訪問,因爲它不是public,可以使得到public

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

注如果要創建實例,則該類也必須是public從形式。

+0

明白了,非常感謝。 – liantokate