最快的方法是IList<string>
从字典中获取并访问它的第七个元素:
checksCollection[checkName][6] = "new value";
但如果我是你,我会将字符串数组中的所有这些值设为自己的类,这样你就不必对索引值进行硬编码,以防万一将来添加或删除其他属性。像这样创建一个类定义:
public class YourClass
{
public string CheckName { get; set; }
public string HostName { get; set; }
public string Port { get; set; }
public string PollInterval { get; set; }
public string AlertEmail { get; set; }
public string AlertSMS { get; set; }
public string AlertURI { get; set; }
}
并更改您的字典定义:
public static IDictionary<string, YourClass> checksCollection =
new Dictionary<string, YourClass>();
然后添加到它(虽然最好你会创建一个YourClass
带参数的构造函数):
public static void addCheck(string checkName, string hostName, string port, string pollInterval, string alertEmail, string alertSMS, string alertURI)
{
checksCollection.Add(checkName, new YourClass() {
CheckName = checkName,
HostName = hostName,
Port = port,
PollInterval = pollInterval,
AlertEmail = alertEmail,
AlertSMS = alertSMS,
AlertURI = alertURI
});
}
然后修改变得简单,无需猜测数组索引:
checksCollection[checkName].AlertURI = "new value";