Hi,
Newbie question:
I wrote this short test code to try to remove duplicate bitarrays
from an arraylist - could someone please give me a hand (thought bitarrays is "built in" so it should work or is "Equals" not working
with IndexOf because BitArrays are in the ArrayList? or ?)
Thanks,Vjeko
using System.Collections;
namespace RemoveDuplicateBitArrays
{
class Class1
{
static void Main(string[] args)
{
//INstantiate an ArrayList and fill it with 4 BitArrays
//which will be used for testing removal of duplicate
// bitarrays
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1[0] = false;
myBA1[1] = true;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
myBA1[0] = false;
myBA1[1] = false;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
myBA1[0] = false;
myBA1[1] = false;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
myBA1[0] = false;
myBA1[1] = true;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
int index;
for(int i=0; i<(arr.Count-1); i++)
{
index=arr.IndexOf(arr, i+1); //compare present
//and next
while( index>i ) //go through arraylist
{
//next bitarray is a duplicate - remove it and
//modify index for next comparison
arr.Remove(index);
if( i<(arr.Count-1) )
{ index=arr.IndexOf(arr, i+1);
}
else
{
index=-1;
}
}
}//for
foreach(BitArray x in arr)
{
int i = 0;
System.Collections.IEnumerator myEnumerator =
myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
Console.WriteLine( "\t[{0}]:\t{1}", i++,
myEnumerator.Current );
Console.WriteLine();
}
}//foreach
}}}
Newbie question:
I wrote this short test code to try to remove duplicate bitarrays
from an arraylist - could someone please give me a hand (thought bitarrays is "built in" so it should work or is "Equals" not working
with IndexOf because BitArrays are in the ArrayList? or ?)
Thanks,Vjeko
using System.Collections;
namespace RemoveDuplicateBitArrays
{
class Class1
{
static void Main(string[] args)
{
//INstantiate an ArrayList and fill it with 4 BitArrays
//which will be used for testing removal of duplicate
// bitarrays
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1[0] = false;
myBA1[1] = true;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
myBA1[0] = false;
myBA1[1] = false;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
myBA1[0] = false;
myBA1[1] = false;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
myBA1[0] = false;
myBA1[1] = true;
myBA1[2] = true;
myBA1[3] = true;
arr.Add(myBA1);
int index;
for(int i=0; i<(arr.Count-1); i++)
{
index=arr.IndexOf(arr, i+1); //compare present
//and next
while( index>i ) //go through arraylist
{
//next bitarray is a duplicate - remove it and
//modify index for next comparison
arr.Remove(index);
if( i<(arr.Count-1) )
{ index=arr.IndexOf(arr, i+1);
}
else
{
index=-1;
}
}
}//for
foreach(BitArray x in arr)
{
int i = 0;
System.Collections.IEnumerator myEnumerator =
myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
Console.WriteLine( "\t[{0}]:\t{1}", i++,
myEnumerator.Current );
Console.WriteLine();
}
}//foreach
}}}