?
Solved

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

Posted on 2008-10-02
3
Medium Priority
?
346 Views
Last Modified: 2008-10-02
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
Comment
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
3 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22627079
why dont you create an array of structure which meets your requirement
0
 
LVL 16

Accepted Solution

by:
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]);
    }
}

Open in new window

0
 
LVL 1

Author Comment

by:lplayer
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

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

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

Join & Ask a Question