Click here to Skip to main content
15,896,496 members
Articles / Programming Languages / C#

MultiList: .NET Generic List with Multiple Sort Orders

Rate me:
Please Sign up or sign in to vote.
3.55/5 (5 votes)
1 Feb 2008CPOL6 min read 44.3K   200   16  
The MultiList class extends the functionality of the generic list. The MultiList class manages multiple sort orders on lists. It is best suited to object lists where searching is required on more than one criteria.
// 
// MultiList library - Copyright 2008 by Michael Moorman / AsAbove.net
// This work is released to the public domain, and may be used for any purpose, without any conditions.
// 
using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
	public class Person : System.IEquatable<Person>
	{
		public enum Profession
		{
			Teacher,
			Nurse,
			Barber,
			Welder,
			Carpenter,
			Lawyer
		};

		private string _name;
		private int _age;
		private Profession _career;
		private static int _static_sequence = 0;
		private int _sequence;

		public Person (string name, int age, Profession career)
		{
			_name = name;
			_age = age;
			_career = career;
			lock (typeof (Person))
			{	
				_sequence = ++_static_sequence;
			}
		}

		public string Name
		{
			get { return _name; }
		}

		public int Age
		{
			get { return _age; }
		}

		public Profession Career
		{
			get { return _career; }
		}

		public int Sequence
		{
			get { return _sequence; }
		}

		public bool Equals (Person p)
		{
			return Sequence == p.Sequence;
		}

	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions