- Home /
Question by
paternostrox · Sep 17, 2020 at 03:47 PM ·
mathdeclaration
Unusual brackets in int3 declaration, what does it mean? (Unity.Mathematics)
So I'm having trouble understanding a single line of code. I simplified the code I actually saw but the concept is the same, an int3 variable is declared and in it's declaration square brackets are used in an unusual manner, can someone tell what it's doing?
int x,y,z;
// assign a value to x,y,z here
int3 position = new int3 {[2] = x, [1] = y, [0] = z}; // what does this do exactly?
Comment
Answer by hexagonius · Sep 18, 2020 at 08:09 AM
I think this explains it pretty well:
https://riptutorial.com/csharp/example/53/csharp-6-index-initializers
In your example code someone intended to assign xyz in reverse order an since int3 is a struct and as such has an array indexer it can be used in an object initializer
Your answer
![](https://koobas.hobune.stream/wayback/20220613012032im_/https://answers.unity.com/themes/thub/images/avi.jpg)