Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Get and set value in Syste.Collection.BitArray using C# in .net 2.0.

Author: Zunnair
Download Source Code : 833_BitArrayApp.zip

In this simple article you will learn that how to get and set values in BitArray Collection

 Create new c# project. Drag two buttons and eight check boxes on the windows form.

 

First declare global ArrayBit

System.Collections.BitArray birarray;

 

Now write following code on form load event:

 

C#

private void Form1_Load(object sender, EventArgs e)

        {

            checkBox1.Text = "Value 1";

            checkBox2.Text = "Value 2";

            checkBox3.Text = "Value 3";

            checkBox4.Text = "Value 4";

            checkBox5.Text = "Value 5";

            checkBox6.Text = "Value 6";

            checkBox7.Text = "Value 7";

            checkBox8.Text = "Value 8";

 

            button1.Text = "Load Byte Array Values";

            button2.Text = "Save Current Values";

           

 

            this.Text = "BitArray Application";

            //Initializaion of array

            birarray = new System.Collections.BitArray(8, true);

 

            checkBox1.Checked = birarray.Get(0);

            checkBox2.Checked = birarray.Get(1);

            checkBox3.Checked = birarray.Get(2);

            checkBox4.Checked = birarray.Get(3);

            checkBox5.Checked = birarray.Get(4);

            checkBox6.Checked = birarray.Get(5);

            checkBox7.Checked = birarray.Get(6);

            checkBox8.Checked = birarray.Get(7);

           

        }

 

VB

 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        checkBox1.Text = "Value 1"

        checkBox2.Text = "Value 2"

        checkBox3.Text = "Value 3"

        checkBox4.Text = "Value 4"

        checkBox5.Text = "Value 5"

        checkBox6.Text = "Value 6"

        checkBox7.Text = "Value 7"

        checkBox8.Text = "Value 8"

 

        button1.Text = "Load Byte Array Values"

        button2.Text = "Save Current Values"

 

 

        Me.Text = "BitArray Application"

        'Initializaion of array

        birarray = New System.Collections.BitArray(8, True)

 

        checkBox1.Checked = birarray.[Get](0)

        checkBox2.Checked = birarray.[Get](1)

        checkBox3.Checked = birarray.[Get](2)

        checkBox4.Checked = birarray.[Get](3)

        checkBox5.Checked = birarray.[Get](4)

        checkBox6.Checked = birarray.[Get](5)

        checkBox7.Checked = birarray.[Get](6)

        checkBox8.Checked = birarray.[Get](7)

 

    End Sub

 

Now write code on buttons events

 

C#

 

private void button1_Click(object sender, EventArgs e)

        {

            checkBox1.Checked = birarray.Get(0);

            checkBox2.Checked = birarray.Get(1);

            checkBox3.Checked = birarray.Get(2);

            checkBox4.Checked = birarray.Get(3);

            checkBox5.Checked = birarray.Get(4);

            checkBox6.Checked = birarray.Get(5);

            checkBox7.Checked = birarray.Get(6);

            checkBox7.Checked = birarray.Get(7);

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            birarray.Set(0, checkBox1.Checked);

            birarray.Set(1, checkBox2.Checked);

            birarray.Set(2, checkBox3.Checked);

            birarray.Set(3, checkBox4.Checked);

            birarray.Set(4, checkBox5.Checked);

            birarray.Set(5, checkBox6.Checked);

            birarray.Set(6, checkBox7.Checked);

            birarray.Set(7, checkBox8.Checked);

 

        }

VB

 

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        checkBox1.Checked = birarray.[Get](0)

        checkBox2.Checked = birarray.[Get](1)

        checkBox3.Checked = birarray.[Get](2)

        checkBox4.Checked = birarray.[Get](3)

        checkBox5.Checked = birarray.[Get](4)

        checkBox6.Checked = birarray.[Get](5)

        checkBox7.Checked = birarray.[Get](6)

        checkBox7.Checked = birarray.[Get](7)

    End Sub

 

    Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)

        birarray.[Set](0, checkBox1.Checked)

        birarray.[Set](1, checkBox2.Checked)

        birarray.[Set](2, checkBox3.Checked)

        birarray.[Set](3, checkBox4.Checked)

        birarray.[Set](4, checkBox5.Checked)

        birarray.[Set](5, checkBox6.Checked)

        birarray.[Set](6, checkBox7.Checked)

        birarray.[Set](7, checkBox8.Checked)

 

    End Sub

 

Bit Array can be very usefull in some of your application.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to perform create, open and close operations on files using “FILE CLASS” using SYSTEM.IO Namespace in c#.net 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net