I have a dictionary
public static IDictionary<string, IList<string>> checksCollection =
new Dictionary<string, IList<string>>();
I add to the dictionary as follows:
public static void addCheck(string checkName, string hostName,
string port, string pollInterval, string alertEmail,
string alertSMS, string alertURI)
{
checksCollection.Add(checkName, new[] { checkName, hostName, port,
pollInterval, alertEmail, alertSMS, alertURI });
}
How would it be possible to change the alertURI list value?
Quickest way, by getting the
IList<string>from the dictionary and accessing its seventh element:But if I were you, I’d make all those values in the string array its own class so you don’t have to hardcode the index values, just in case you add or remove additional properties in the future. Create a class definition like so:
And change your dictionary definition:
And then to add to it (although preferably you would create a constructor on
YourClassthat takes the parameters):And then modifying becomes straightforward with no guesswork of array indices: