Solved

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

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

Industry Leaders: 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

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.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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