我有一个类似这样的类(这是代码的子集)
public struct overlay
{
[FieldOffset(0)]
public Byte[] b;
[FieldOffset(0)]
public Int32[] i;
}
class MyClass
{
private overlay data; \\Initialised using data.b=new Byte[4096]
public Int32 site0 { set { data.i[0] = value; } get { return data.i[0]; } }
public Int32 site1 { set { data.i[1] = value; } get { return data.i[1]; } }
public String s
{
get { return System.Text.Encoding.ASCII.GetString(data.b, 8, 16).TrimEnd(' '); }
set { System.Text.Encoding.ASCII.GetBytes(value.PadRight(16)).CopyTo(data.b, 8); }
}
public Int32 site2 { set { data.i[5] = value; } get { return data.i[5]; } }
}
我目前访问这样的站点变量...
MyClass m=new MyClass();
m.site0=1;
m.site1=1;
m.site2=1;
我想像这样访问它们..
MyClass m=new MyClass();
for (Int32 i=0; i<m.sites.Count; ++i)
m.sites[i]=1;
谁能建议我怎么做?