まず、ハッシュテーブルとその値を宣言します。ハッシュテーブルエントリのキーはGUIDであり、値は文字列値が少数のオブジェクトです。キーでハッシュテーブルobjを取得し、公開プロパティを変更します。
Guid g = Guid.NewGuid();
Hashtable hash = new Hashtable();
InstallationFiles instFiles = new InstallationFiles(string1, string2, string3);
hash.Add(g, instFiles);
//...add many other values with different GUIDs...
私の目標は、ユーザーに文字列1、文字列2、文字列3を編集できるようにすることです。長い話を短くカットするために、私は私が編集する必要がエントリの「GUID gを」得ることができる位置にいます:
public void edit()
{
//here I retrieve the GUID g of the item which has to be edited:
object objectHash = item.Tag;
//here i loop through all hash entries to find the editable one:
foreach(DictionaryEntry de in hash)
{
if(de.Key.ToString() == objectHash)
{
//here I would like to access the selected entry and change string1 -
//the line below is not working.
hash[de.Key].string1 = "my new value";
}
}
}
は、どのように私はこのラインを動作させるのですか?
hash[de.Key].string1 = "my new value";
'' Dictionary ''を使用して、変数を強く型付けし、そのプロパティにアクセスします。 –
usercr