Click here to Skip to main content
12,358,863 members (64,245 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

42.1K views
263 downloads
44 bookmarked
Posted

The Enumerable Enumerator

, 2 Nov 2006
Iterate over your enums, and other things to do with enums.
using System;
using System.Collections.Generic;
using System.Text;

namespace Clifton.Tools.Data
{
    class Program
    {
        enum Test
        {
            A=1,
            B=2,
            C=3,
            D=4,
        }

		/// <summary>
		/// Another example.
		/// </summary>
		enum AlarmBits
		{
			Door=1,
			Window=2,
			Security=4,
			CoinJam=8,
			BillJam=16,
		}

		/// <summary>
		/// Another example.
		/// </summary>
		enum States
		{
			Slow,
			Medium,
			Fast
		}

        static void Main(string[] args)
        {
            Console.WriteLine("First = " + Enumerator<Test>.First);
            Console.WriteLine("Last = " + Enumerator<Test>.Last);
            Console.WriteLine("Previous Or First of A = " + Enumerator<Test>.PreviousOrFirst(Test.A));
            Console.WriteLine("Previous Or First of B = " + Enumerator<Test>.PreviousOrFirst(Test.B));
            Console.WriteLine("Next Or Last of C = " + Enumerator<Test>.NextOrLast(Test.C));
            Console.WriteLine("Next Or Last of D = " + Enumerator<Test>.NextOrLast(Test.D));
			Console.WriteLine("Enumerator low limit (C->B) = " + Enumerator<Test>.PreviousBounded(Test.C, Test.B));
			Console.WriteLine("Enumerator low limit (B->B) = " + Enumerator<Test>.PreviousBounded(Test.B, Test.B));
			Console.WriteLine("Enumerator low limit (A->B) = " + Enumerator<Test>.PreviousBounded(Test.A, Test.B));
			Console.WriteLine("Enumerator high limit (B->C) = " + Enumerator<Test>.NextBounded(Test.B, Test.C));
			Console.WriteLine("Enumerator high limit (C->C) = " + Enumerator<Test>.NextBounded(Test.C, Test.C));
			Console.WriteLine("Enumerator high limit (D->C) = " + Enumerator<Test>.NextBounded(Test.D, Test.C));

            foreach (Test t in Enumerator<Test>.Items())
            {
                Console.WriteLine(t + " = " + Convert.ToInt32(t));
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Marc Clifton
United States United States
Marc is the creator of two open source projects, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.

Marc lives in Philmont, NY.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 2 Nov 2006
Article Copyright 2006 by Marc Clifton
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid