Unique Algorithm

フレームワークにUniqueがないな〜と思って書いてみました。あまりにも簡単に書けてびっくり!Unixでお馴染みのuniqの処理です。

using System;
using System.Collections;

namespace Siokoshou
{
  public class ArrayListWithUnique : ArrayList
  {
    public ArrayListWithUnique() {}
    public ArrayListWithUnique( ICollection c ) : base( c ) {}
    public ArrayListWithUnique( int num ) : base( num ) {}

    public void Unique()
    {
      for ( int i = 0; i < this.Count; i++ )
      {
        for ( int j = i + 1; j < this.Count; j++ )
        {
          if ( this[ i ].Equals( this[ j ] ) )
          {
            RemoveAt( j-- );
          }
        }
      }
    }
  }
}