我想在C#中創建一個設置或返回數組的單個成員的屬性。目前,我有這樣的:在C中暴露數組元素的屬性#
private string[] myProperty;
public string MyProperty[int idx]
{
get
{
if (myProperty == null)
myProperty = new String[2];
return myProperty[idx];
}
set
{
myProperty[idx] = value;
}
}
不過,我得到以下編譯錯誤:
Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
http://www.codeproject.com/KB/cs/csharptips.aspx – 2010-08-23 13:11:15