Color[] colors = new Color[] { color1, color2, color3 };
Edit:
Actually your code too should work⌠it that your exact code? Are you sure you havenât declared the colors array earlier and initialized it later.
Fun fact: Instance variable initializers can not reference each other because their execution order is not determined. Though static field initializers can reference other static fields but their initialization order is also undefined. However it âusuallyâ follows the declaration order, but I would not count on it. See this fiddle as example.
Using static fields from other classes is usually not an issue as the static initialization of a class / types happens âlazilyâ when itâs first accessed. Though if you have static cross references you would again run into the same chicken and egg issue which you should avoid.
In theory the compiler could build a chain of dependencies which field initializer uses what other field. However this can easily cause issues. Also it would be possible to have some kind of cyclic dependencies which could not be resolved. When allowing fields to reference each other, what about properties? What if they are virtual? So a derived class could introduce a cyclic dependency where there was none in the beginning. This just doesnât work
Generally inside a field initializer of instance fields of a class you can not use any data or method from that class itself since itâs not initialized yet. Though you can use static fields or methods in instance fieldâs field initializers.