タイトル | : Re: 構造体のソートについて |
記事No | : 1770 |
投稿日 | : 2005/05/31(Tue) 11:42 |
投稿者 | : ねろ |
こんな方法もあるのかな。 Returnのところにブレイクポイントを置くとクイックソートやってるのがわかる。
Option Strict On Imports System
Private Structure CompanyStaff Implements IComparable Public Code, Name As String Public Function CompareTo(ByVal obj As Object) As Integer Implements _ IComparable.CompareTo Return Me.Code.CompareTo(DirectCast(obj, CompanyStaff).Code) End Function End Structure
'//以下単に確認のコード Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Dim Person As CompanyStaff() ReDim Person(3) Person(0).Code = "0004" : Person(0).Name = "すずき-0004" Person(1).Code = "0003" : Person(1).Name = "あらき-0003" Person(2).Code = "0005" : Person(2).Name = "やまだ-0005" Person(3).Code = "0006" : Person(3).Name = "たなか-0006" Console.WriteLine("ソート前") For Each w As CompanyStaff In Person Console.WriteLine(w.Name) Next Console.WriteLine("ソート後") Array.Sort(Person) For Each w As CompanyStaff In Person Console.WriteLine(w.Name) Next End Sub
|