Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Saving 5 56
What .NET website keeps me current? 9 55
Linq Help 1 35
Problem to error 4 43
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

16 Experts available now in Live!

Get 1:1 Help Now