You don't need if(boolThing[0]==true). You can just use `if (boolThing[0]))
You can also use binary operators to evaluate several boolean values together.
if((bools[0]&bools[3]) && !(bools[1]|bools[2]|bools[4]|bools[5])
You can use a BitArray to easily work with a collection of booleans and it will be much more efficient.
The most efficient method is going to be to use numeric types.
The easiest way to do this would to be to use an enum, with flags. You can use binary operators to set or clear the flags of the enum.
[Flags] public enum MyBoolFlag { None, Bool0 = 1<<0, Bool1 = 1 << 1, Bool2 = 1 << 2, Bool3 = 1 << 3, Bool4 = 1 << 4, Bool5 = 1 << 5, //etc }
And you use binary operations to set the flags.
MyBoolFlag myFlag = MyBoolFlag.Bool0|MyBoolFlag.Bool1|MyBoolFlag.Bool3;
In your code, you can now check:
if(myFlag == MyBoolFlag.Bool0|MyBoolFlag.Bool3) { }
You can define constants for various conditions.
const MyBoolFlag myCondition1 = MyBoolFlag.Bool0|MyBoolFlag.Bool3;
And then check:
if(myFlag == myCondition1) { }
You can also do some more legwork and use types such as native types such byte and int directly.
You can use a single byte to save 8 boolean values as flag masks each representing a power of two. A uint32 can save 32 and a uint64 can save 64 booleans.
This has a huge performance boost because a boolean is stored as uint32 which means it uses 4 bytes of data and you can pack 32 booleans in an uint32 when you use the bits ask boolean flags.
Programs will also execute faster because the CPU evaluate myFlag == myCondition1 in a single operation using the native machine word. Otherwise many instructions are needed to put lookup boolean values in an array and compare them. .Net will also do some sanity checks making sure your array isn't null, your indexes aren't out of range and then need to move pointers around to lookup those values.
For convenience you can create a bitarray from an array of booleans and then use it to initialize an array of numeric types with their appropriate flags set.
For example:
bool[] bools = new bool[] { true, false, false, true, false, false }; BitArray bitArray = new BitArray(new bool[] { true, false, false, true, false, false }); int[] array = new int[1]; bitArray.CopyTo(array, 0); int value = array[0];
The point of this is 'value' will be 9 if bools[0] = true and bools[3] true.
So your code would cleanly be:
if(value==9) // bools[0]&bools[1]==true;
You can also create constant masks to check different numerical values to check if different bits are set in your numerical values or to manipulate the bits using binary operations.
You could get more efficiency by setting the numeric values using binary operations.
uint32 myFlag= 1|(1<<3);
boolThing[0] == truecan be onlyboolThing[0].== trueis redundant.