If they are literally just "levels", then individual properties don;g make a lot of sense - the names aren't particularly useful, and having them as an array makes some code rather simpler: you can loop through them easily for example when saving to non-volatile storage.
I'd go with the array (but do note that your code won't compile: C# is case sensitive, so "Public" and "Class" are not the same as
public
and
class
; the colon at the end of the array based version is wrong; the whole property declaration is wrong for both types).
public class MyClass
{
public const int MaxColors = 7;
public Color[] ColorLevels { get; set; } = new Color[MaxColors];
}
Quote:
Thanks, OriginalGriff. That did the trick for a known number of colors. What if I want to make it a variable number of colors, only known at the time the object is instatiated. How do I use a property to pass in the and read the number of items in the array?
That's easy: instead of allocating the array when you declare the property, you allocate it as part of your class constructor:
public class MyClass
{
public Color[] ColorLevels { get; private set; }
public MyClass(int maxColours)
{
ColorLevels = new Color[maxColours];
}
}
Your code can check how many levels are allowed by querying the ColourLevels.Length property.