Прежде всего объявляю хэш-таблицу и ее значения. Ключом записи хэш-таблицы является GUID, а значение - это объект с несколькими строковыми значениями.Получить hashtable 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, string2, string3. Чтобы вырезать Короче говоря, я нахожусь в таком месте, где я могу получить «GUID г» в записи, которая должна быть отредактирован:
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";
Используйте '' Словарь '', чтобы получить строго переменную типа и получить доступ к его свойствам –
usercr