此語言不支援屬性、索引子或事件 'property';請試著直接呼叫存取子方法 'accessor'
您的程式碼正在取用的物件具有預設的索引屬性,並嘗試使用索引語法。 若要解決這個錯誤,請呼叫屬性的存取子方法。 如需索引子和屬性的詳細資訊,請參閱索引子。
下列範例會產生 CS1546。
範例 1
此程式碼範例包含編譯成 .dll 的 .cpp 檔案和使用該 .dll 的 .cs 檔案。 下列程式碼用於 .dll 檔案,並定義 .cs 檔案中程式碼存取的屬性。
// CPP1546.cpp
// compile with: /clr /LD
using namespace System;
public ref class MCPP
{
public:
property int Prop [int,int]
{
int get( int i, int b )
{
return i;
}
}
};
範例 2
這是 C# 檔案。
// CS1546.cs
// compile with: /r:CPP1546.dll
using System;
public class Test
{
public static void Main()
{
int i = 0;
MCPP mcpp = new MCPP();
i = mcpp.Prop(1,1); // CS1546
// Try the following line instead:
// i = mcpp.get_Prop(1,1);
}
}