私はC#を使用していますが、これについてはあまり経験がありません(これまで、ほとんどjava / php / javascriptを使用してきました)
私が欲しいのは、いくつかのデータを保存するクラスです。このデータは、他の1つのクラスによってのみ書き込むことができますが、プログラム内の他のクラスによって読み取ることはできます。
このようなもの:
public class DataObtainer{
DataItem[] Items;
public DataObtainer(){
Items = new DataItem[20];
}
public void Update(){
Items[0].SomeProperty = 5;//Being able to change SomeProperty
}
//Class only contains properties
public class DataItem{
public int SomeProperty;
}
}
public class AnyOtherClass{
public void SomeMethod(){
DataObtainer do = new DataObtainer();
//What I want:
DataItem di = do.items[0];
Console.WriteLine(di.SomeProperty);//Being able to read SomeProperty
di.SomeProperty = 5;//Not allow this, not being able to change SomeProperty
}
}