- Home /
error CS0236: A field initializer cannot reference the nonstatic field, method, or property
I'm trying to make an Array of Booleans. As you can see below. But I'm getting an Error, not sure why I got it. It says the last line of my code below is the source of the error
public bool F1X1 = false;
public bool F1Y1 = false;
public bool F1Z1 = false;
public bool F2X2 = false;
public bool F2Z2 = false;
public bool F3Y2 = false;
public bool[] isActive = new bool[6]{F1X1,F1Y1,F1Z1,F2X2,F2Z2,F3Y2};
Actually the error means exactly the same as it says. You cannot assign values that are not static or constant while creating objects.
wat is the exact motive here?
Answer by ChrisJoosten · Mar 20, 2014 at 12:50 PM
Never mind! Already fixed it!
The problem was I initialized the boolean array at the wrong place.
I placed it in a function and the error is gone :)
void Start(){
isActive = new bool[6]{F1X1,F1Y1,F1Z1,F2X2,F2Z2,F3Y2};
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613140727im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how can i check if index exists? 2 Answers
Multiple Cars not working 1 Answer
C# array not behaving as expected 0 Answers
IndexOutOfRangeException help on debug 3 Answers
Cannot convert float to int when only using floats (C#) 3 Answers