G
Guest
I am getting runtime errors accessing BitArray objects with the error being;
Object reference not set to an instance of an object
I though the 'new' operator created the instance and everything was all set to go?
What is the correct way to set up the bit arrays?
Code that shows this problem is listed below;
using System;
using System.Collections;
// See 7.5.10.2 Array creation expressions in the C# language specification
public struct My_sru
{
public BitArray[] My_1d_ary;
public BitArray[][] My_2d_ary;
public BitArray[,] My_2d_rectangular_ary;
}
public class Test_compile_cls
{
static My_sru s_my_sru;
[STAThread]
public static void Main(string[] p_command_line_arguments_str_ary)
{
//#---1---- Declare and set local state space --------------------------------------------:_:---#
int l_idx = 0;
s_my_sru.My_1d_ary = new BitArray [10];
s_my_sru.My_2d_ary = new BitArray [] [] {new BitArray[10], new BitArray[10]};
s_my_sru.My_2d_rectangular_ary = new BitArray [10,10];
//#---2---- Initilize arrays -------------------------------------------------------------:_:---#
s_my_sru.My_1d_ary[0].Length = 32;
// Object reference not set to an instance of an object
s_my_sru.My_1d_ary [1].SetAll( false);
s_my_sru.My_2d_ary [2] [2].SetAll( true);
s_my_sru.My_2d_rectangular_ary[3,3].SetAll( true);
for( l_idx = 0; l_idx < 10; l_idx ++)
{
s_my_sru.My_1d_ary [l_idx].SetAll( false);
}
//#---3---- Set several bits -------------------------------------------------------------:_:---#
s_my_sru.My_2d_rectangular_ary[3,3].Set(0,false);
s_my_sru.My_2d_rectangular_ary[3,3].Set(1,true);
s_my_sru.My_2d_rectangular_ary[3,3].Set(2,false);
s_my_sru.My_2d_rectangular_ary[3,3].Set(3,true);
//#---4---- Return -----------------------------------------------------------------------:_:---#
} // end main
} // end class
Object reference not set to an instance of an object
I though the 'new' operator created the instance and everything was all set to go?
What is the correct way to set up the bit arrays?
Code that shows this problem is listed below;
using System;
using System.Collections;
// See 7.5.10.2 Array creation expressions in the C# language specification
public struct My_sru
{
public BitArray[] My_1d_ary;
public BitArray[][] My_2d_ary;
public BitArray[,] My_2d_rectangular_ary;
}
public class Test_compile_cls
{
static My_sru s_my_sru;
[STAThread]
public static void Main(string[] p_command_line_arguments_str_ary)
{
//#---1---- Declare and set local state space --------------------------------------------:_:---#
int l_idx = 0;
s_my_sru.My_1d_ary = new BitArray [10];
s_my_sru.My_2d_ary = new BitArray [] [] {new BitArray[10], new BitArray[10]};
s_my_sru.My_2d_rectangular_ary = new BitArray [10,10];
//#---2---- Initilize arrays -------------------------------------------------------------:_:---#
s_my_sru.My_1d_ary[0].Length = 32;
// Object reference not set to an instance of an object
s_my_sru.My_1d_ary [1].SetAll( false);
s_my_sru.My_2d_ary [2] [2].SetAll( true);
s_my_sru.My_2d_rectangular_ary[3,3].SetAll( true);
for( l_idx = 0; l_idx < 10; l_idx ++)
{
s_my_sru.My_1d_ary [l_idx].SetAll( false);
}
//#---3---- Set several bits -------------------------------------------------------------:_:---#
s_my_sru.My_2d_rectangular_ary[3,3].Set(0,false);
s_my_sru.My_2d_rectangular_ary[3,3].Set(1,true);
s_my_sru.My_2d_rectangular_ary[3,3].Set(2,false);
s_my_sru.My_2d_rectangular_ary[3,3].Set(3,true);
//#---4---- Return -----------------------------------------------------------------------:_:---#
} // end main
} // end class