Comparison<T>

Overview

The Blocks that has two parameters and returns a boolean value. This block is used to compare two objects of specific type.

Use case

You can use this block to represent a method that will perform object comparison.

For example if you need to sort a list you can use List<T> method that takes an Comparison<T> block:

var Items := new List<Sugar.String>;
Items.Add("C");
Items.Add("A");
Items.Add("B");
  
writeLn("Original: ");
Items.ForEach(item -> write(item));
  
Items.Sort((x, y) -> x.CompareTo(y));

writeLn;
writeLn("Sorted: ");
Items.ForEach(item -> write(item));

Output:

Original:
CAB
Sorted:
ABC

Location

See Also

  • Blocks
  • Anonymous Methods
  • Anonymous Methods