Embarcadero Delphi                
            Generics
        
        
            
    Szukaj…
Sortuj tablicę dynamiczną za pomocą ogólnego TArray.Sort 
uses
  System.Generics.Collections, { TArray }
  System.Generics.Defaults; { TComparer<T> }
var StringArray: TArray<string>; { Also works with "array of string" }
...
{ Sorts the array case insensitive }
TArray.Sort<string>(StringArray, TComparer<string>.Construct(
  function (const A, B: string): Integer
  begin
    Result := string.CompareText(A, B);
  end
));
        Proste użycie TList 
var List: TList<Integer>;
...
List := TList<Integer>.Create; { Create List }
try
  List.Add(100); { Add Items }
  List.Add(200);
  WriteLn(List[1]); { 200 }
finally
  List.Free;
end;
        Malejąco z listy TList  czyniąc to konkretnym 
type
  TIntegerList = class(TList<Integer>)
  public
    function Sum: Integer;
  end;
...
function TIntegerList.Sum: Integer;
var
  Item: Integer;
begin
  Result := 0;
  for Item in Self do
     Result := Result + Item;
end;
        Sortuj listę 
var List: TList<TDateTime>;
...
List.Sort(
  TComparer<TDateTime>.Construct(
    function(const A, B: TDateTime): Integer
    begin
      Result := CompareDateTime(A, B);
    end
  )
);
    
    
    
    
    Modified text is an extract of the original Stack Overflow Documentation
        Licencjonowany na podstawie CC BY-SA 3.0
        Nie związany z Stack Overflow