Just came across this little generic gem:
string[] input = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
int[] output = Array.ConvertAll<string, int>(input, delegate(string s) { return int.Parse(s); });
I have a number of web.config files that store lists of integers as comma separated strings. This is a clean way to convert it all to an int array. (It is in need of some exception handling.)
<appSettings>
<add key="MachineIDs" value="44,3,43,566" />
</appSettings>
private int[] GetConfigIntArray(string key)
{
string[] values = ConfigurationManager.AppSettings[key].Split(',');
return Array.ConvertAll<string, int>(values, delegate(string s) { return int.Parse(s); });
}
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010, Andrew Robinson
E-mail