Use BitArray collection as Flag : BitArray « Collections Data Structure « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » Collections Data Structure » BitArrayScreenshots 
Use BitArray collection as Flag


using System;
using System.Collections;

public class Starter {
    public static void Main() {
        Hashtable employees = new Hashtable();
        employees.Add("A100"new Employee("Ben", true, false, true));
        employees.Add("V100"new Employee("Valerie", false, false, true));
        Participation((Employee)employees["A100"]);
        Participation((Employee)employees["V100"]);
    }

    public static void Participation(Employee person) {
        Console.WriteLine(person.Name + ":");
        if (person.InProfitSharing) {
            Console.WriteLine(" Participating in Profit Sharing");
        }
        if (person.InHealthPlan) {
            Console.WriteLine(" Participating in Health Plan");
        }
        if (person.InCreditUnion) {
            Console.WriteLine(" Participating in Credit Union");
        }
    }
}

public class Employee {

    public Employee(string emplName) {
        propName = emplName;
        eflags.SetAll(true);
    }

    public Employee(string emplName,
                    bool profitSharing,
                    bool healthPlan,
                    bool creditUnion) {
        propName = emplName;
        InProfitSharing = profitSharing;
        InHealthPlan = healthPlan;

        InCreditUnion = creditUnion;
    }

    private BitArray eflags = new BitArray(3);

    public bool InProfitSharing {
        set {
            eflags.Set(0, value);
        }
        get {
            return eflags.Get(0);
        }
    }

    public bool InHealthPlan {
        set {
            eflags.Set(1, value);
        }
        get {
            return eflags.Get(1);
        }
    }

    public bool InCreditUnion {
        set {
            eflags.Set(2, value);
        }
        get {
            return eflags.Get(2);
        }
    }

    private string propName;
    public string Name {
        get {
            return propName;
        }
    }
}
           
       
Related examples in the same category
1. Demonstrate BitArrayDemonstrate BitArray
2. illustrates the use of a BitArrayillustrates the use of a BitArray
3. illustrates the use of BitArray methodsillustrates the use of BitArray methods
w_ww.__j__a___va__2___s__._c___o_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.