look at the overloads for Color.FromArgb
, they all expect int
to be passed in. So no, you can't just pass in a string and expect it to work. However it is not hard to turn your string in to a set of ints.
public Color[] convertToColorArray() {
for (int i = 0; i < rows; i++) {
//This gives us an array of 3 strings each representing a number in text form.
var splitString = stringArray[i].Split(',');
//converts the array of 3 strings in to an array of 3 ints.
var splitInts = splitString.Select(item => int.Parse(item)).ToArray();
//takes each element of the array of 3 and passes it in to the correct slot
colorArray[i] = System.Drawing.Color.FromArgb(splitInts[0], splitInts[1], splitInts[2]);
}
return colorArray;
}
This code all assumes your source file is well formed so that string.Split
will always return at least 3 arrays and int.Parse
will never fail at parsing the input.