MJW Posted October 9, 2022 Posted October 9, 2022 I probably should know this, but is there any compact way of initializing a 2D array of ColorBgra values? Like this, but with ColorBgras: int[,] = { {0, 1}, {2, 3}, (4, 5} }; Quote
BoltBait Posted October 9, 2022 Posted October 9, 2022 Easy: ColorBgra[,] myArrayOfColors = new ColorBgra[2, 2] { { ColorBgra.Red, ColorBgra.Yellow }, { ColorBgra.Green, ColorBgra.Blue }, }; Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
MJW Posted October 9, 2022 Author Posted October 9, 2022 2 hours ago, BoltBait said: Easy: But I need it for arbitrary colors, not jut predefined. EDIT: For some reason, right or wrong, I was thinking that you can only use constants in array initializers, not methods like ColorBgra.FromBgra(0, 1, 2, 3). Now I'm not so sure. I'll look it up tomorrow. I tend to forget those details on things I haven't used for a while. Also, even that wouldn't work out all that well for what I'm thinking about. It's a rather large array, so having each entry require such a long string would take up a lot of space. I think maybe the best thing is to just use an array of unsigned ints, convert it, element by element, to a ColorBgra array in the program, then set the int array to null and let the garbage collector handle it. Far from elegant, but it would probably work okay for my idea. Oh, and thanks for the answer to a question I probably should have thought a little more about before bothering people with. EDIT 2: Pointlessly driving this thing into the ground, I think what I was remembering with regard to initializing variables with only constants has to do with constant variables -- or something like that. Is it any wonder I have to keep a C# reference book handy when writing programs? Quote
BoltBait Posted October 9, 2022 Posted October 9, 2022 So, don't use an initializer: ColorBgra[,] myArrayOfColors = new ColorBgra[2, 2]; myArrayOfColors[0, 0] = ColorBgra.Red; myArrayOfColors[0, 1] = ColorBgra.Green; : Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.