Sort:  

It is pseudocode but based on C# which I have used.