User Tools

Site Tools


codesamples:sorting_collection

Sorting a collection

using System.Collections.Generic 
using System.Linq
using System
                       
// Important: include at least System, System.Core, System.Linq

function Start( ) as void
  local oTrackList as List<Track>
	
  oTrackList := List<Track>{} 
  oTrackList:Add( Track{ 12 } )
  oTrackList:Add( Track{ 23 } )
  oTrackList:Add( Track{ 34 } )
  oTrackList:Add( Track{ 45 } )
  oTrackList:Add( Track{ 56 } )
  oTrackList:Add( Track{ 67 } )
  foreach oTrack as Track in oTrackList
    System.Console.WriteLine( "Track " + oTrack:Start:ToString() )
  next
	
  System.Console.WriteLine( "Sorted now..." )
  oTrackList := oTrackList:orderbyDescending( {|o| o:Start } ):ToList()
	
//	var oSortedList := from oTrack as Track in oTrackList;
//                      orderby oTrack:Start descending;
//                      select oTrack
//	System.Console.WriteLine( "result object is of type " + oSortedList:GetType():Name )	
							
  foreach oTrack as Track in oTrackList
    System.Console.WriteLine( "Track " + oTrack:Start:ToString() )
next
	
return

class Track

constructor( nStart as int )
	
  self:Start := nStart
	
return
	
property Start as int auto
	
end class
codesamples/sorting_collection.txt · Last modified: 2018/05/30 15:21 by wolfgangriedmann