DelegateFunction CompareFunc(ByVal X AsInteger,ByVal Y AsInteger)AsBoolean 'Delegate委托
Function IsSmaller(ByVal X AsInteger,ByVal Y AsInteger)AsBoolean Return X < Y EndFunction
Function IsBigger(ByVal X AsInteger,ByVal Y AsInteger)AsBoolean Return X > Y EndFunction
Sub MySort(ByVal obj()AsInteger,ByVal CompareMethod As CompareFunc) Dim I, J, Tmp AsInteger For I = 0 To obj.Length - 2 For J = I + 1 To obj.Length - 1 If CompareMethod.Invoke(obj(J), obj(I))Then Tmp = obj(J) obj(J)= obj(I) obj(I)= Tmp EndIf Next Next EndSub
Sub Show(ByVal obj()AsInteger) Dim I AsInteger For I = 0 To obj.Length - 1 Console.Write("{0},", obj(I)) Next Console.WriteLine() EndSub
Sub Main() Dim IntArray()AsInteger={34, 21, 54, 32, 12} Dim CompareIt As CompareFunc