Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# How do I create an array (8x8) of BitArrays (16 bits).

Posted on 2008-10-02
Medium Priority
350 Views
I awarded the points as the question was answered, the answer being:

BitArray[,] board = new BitArray[8, 8];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
board[i, j] = new BitArray(16);
}
}

However, my question evolves.....what if I want the 8x8 Array to contain a Struct, so that each square on the board has an int colour and a 16 bitArray , and an int array [3]

0
Question by:lplayer
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 26

Expert Comment

ID: 22627079
why dont you create an array of structure which meets your requirement
0

LVL 16

Accepted Solution

CuteBug earned 2000 total points
ID: 22627085
Define the struct as

``````struct Square
{
int colour;
BitArray bitArray;
int[] array;

public Square(int clr, BitArray bArr, int[] arr)
{
colour = clr;
bitArray = bArr;
array = arr;
}
}

You can initialize your array like this

Square[,] board = new Square[8, 8];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
board[i, j] = new Square(0, new BitArray(16), new int[3]);
}
}
``````
0

LVL 1

Author Comment

ID: 22627485
Thanks CuteBug,

board[3, 3].bitArray[0] = true;
board[2, 2].colour = 1;
board[1, 1].array[2] = 5

For completeness for other lost souls trying to fathom out Structs/arrays, all the above work
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
###### Suggested Courses
Course of the Month9 days, 2 hours left to enroll

#### 604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.