Solved

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

Posted on 2008-10-02
3
337 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
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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now