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
Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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