Direct Extensions
Extensions allow you to add new functionality to a type without modifying its original definition. Use the extend keyword to declare an extension, followed by the type being extended and the new members enclosed in braces.
Extensions can add member functions, member properties, and operator overloading functions. The code on the right adds three utility functions to the Int64 type: isEven() to check for even numbers, isPositive() to check for positive numbers, and abs() to calculate absolute values.
Instances of the extended type can call extension functions just like native methods. Extensions only add behavior without changing the type itself or breaking the encapsulation of the original type.
private members of the extended type, nor can they shadow existing members.Click Run to see how the extended Int64 uses the new methods, and try adding extension functions to String.