when I try to assign a value right after the declaration it gives an error saying the name does not exist in the current context

but when I do it inside a function it works
(I have started recently it is a dumb question probably)
when I try to assign a value right after the declaration it gives an error saying the name does not exist in the current context

but when I do it inside a function it works
(I have started recently it is a dumb question probably)
Your first line is a declarative statement which can only be placed in a type declaration such as a class or struct. Your second line is executable code which can only appear in a method body.
Yes, technically the = new bool[5]; is also executable code, but this is an exception as this is a “field initializer”. The field initializers are actually grouped together and executed before the constructor.
So your second line has to be inside a method. Maybe inside Awake or Start. Though keep in mind that a public array of a serializable type will be serialized in the inspector. So you could simply set the initial values in the inspector.
Note that you can give initial values for your array by doing
public bool[] something = new bool[]{true, false, false, false, false};
Though as I said, the array would be serialized in the inspector. So those initial values would ONLY apply when you create a new instance of that component. Changing the values after the component was attached has no effect since the values are already serialized and Unity will overwrite the values you set in the field initializer with the ones that has been edited in the inspector.