[CSharp.net] Collection oder array?

Alexander Zeitler csharp.net at glengamoi.com
Tue, 18 May 2004 11:08:00 +0200


Hallo,

> 
> Das gibt mir aber den Fehler das ich nicht von GISPoint zu 
> GISPoint[] wandeln kann ...
> auch klar ...
> Aber ich habe jetzt keine Ahnung wie ich die (Nennt man das 
> so:) Collection - Fähigkeit meiner
> Klasse geben kann ....
> 

Du könntest Dir einen Ableitung der ArrayList erstellen,
die dann die GISPoint-Objekte aufnimmt.

Hier mal ein Sample aus dem TimeTracker Kit:

using System;
using System.Collections;

namespace ASPNET.StarterKit.TimeTracker.BusinessLogicLayer
{

=09
//*********************************************************************
	//
	// CategoriesCollection Class
	//
	// The CategoriesCollection Class inherits from ArrayList.  It has
its own implemenation 
	// of Sort based on the sortable Category fields.
	//
=09
//*********************************************************************

	public class CategoriesCollection : ArrayList
	{
		public enum CategoryFields
		{
			Abbreviation,
			Duration,
			InitValue,
			Name
		}

		public void Sort(CategoryFields sortField, bool isAscending)
		{
			switch (sortField) 
			{
				case CategoryFields.Name:
					base.Sort(new NameComparer());
					break;
				case CategoryFields.Abbreviation:
					base.Sort(new
AbbreviationComparer());
					break;
				case CategoryFields.Duration:
					base.Sort(new DurationComparer());
					break;
			}

			if (!isAscending) base.Reverse();
		}

		private sealed class NameComparer : IComparer 
		{
			public int Compare(object x, object y)
			{
				Category first = (Category) x;
				Category second = (Category) y;
				return first.Name.CompareTo(second.Name);
			}
		}

		private sealed class AbbreviationComparer : IComparer 
		{
			public int Compare(object x, object y)
			{
				Category first = (Category) x;
				Category second = (Category) y;
				return
first.Abbreviation.CompareTo(second.Abbreviation);
			}
		}

		private sealed class DurationComparer : IComparer 
		{
			public int Compare(object x, object y)
			{
				Category first = (Category) x;
				Category second = (Category) y;
				return
first.EstDuration.CompareTo(second.EstDuration);
			}
		}
	}
}


Gruss

Alex

Kommt zur .NET Community Conference in Karlsruhe
http://www.dotnetcommunityconference.com