I am working with RGB colour data in a C# (WPF) app, and find myself with a lot of cut and pasted code along the lines of
totals.red += currentPixel.red;
totals.green += currentPixel.green;
totals.blue += currentPixel.blue;
I'd like to reduce this copy-pasting and vulnerability to copy-paste errors. I could use arrays of size 3 around the place, but accessing those by number reduces readability.
I'd like to write something like this:
for (col = all colours) {
totals[col] += currentPixel[col];
}
I'd know how to go about this in C, but am unfamiliar with C#. Something with enums?
Edit: Made the example make more sense.
red,thing, andotherthing?red,greenandblueall members of a type, or are just just hanging around on their own? If the former, which type, if the latter, why aren't they grouped together?