Site Tools


This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:sortkeyvalues [2015/09/14] (current)
Line 1: Line 1:
 +====== More on Sorting Key-Value Pairs ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to sort an array of key-value pairs in RhinoScript.//​
 +=====Also See=====
 +[[developer:​quicksortkeyvaluepair|Key-Value pair QuickSort algorithm]]
 +How does one sort an array of key-value pairs using RhinoScript?​
 +The .NET Framework'​s SortedList class provides a hash table with automatically sorted key-value pairs. The available methods and properties for SortedList are very similar to the ones available in [[dotnetsort|ArrayList]]
 +The following sample code creates a SortedList and populates it with some key-value pairs:
 +<code vb>
 +Set SortedList = CreateObject("​System.Collections.Sortedlist"​)
 +SortedList.Add "​First",​ "​Hello"​
 +SortedList.Add "​Second",​ ","​
 +SortedList.Add "​Third",​ "​Rhino"​
 +SortedList.Add "​Fourth",​ "​!"​
 +For i = 0 To SortedList.Count - 1
 +  Rhino.Print SortedList.GetKey(i) & vbTab & SortedList.GetByIndex(i)
 +Note, SortedList only sorts the list by keys. It is not possible to sort the list by values.
 +{{tag>​Developer RhinoScript}}
developer/scriptsamples/sortkeyvalues.txt ยท Last modified: 2015/09/14 (external edit)