length()
The length()
system function can be used to determine the length of Arrays, Collections (anything that implements ICollection
or ICollection<T>
) and String. It is a convenient way to call API-specific properties (such as .Length
, .Count
and the like) in a more platform and API agnostic manner. length()
is also nil
/null
-safe, and will return a length of 0
for a nil argument, saving an additional extra check compared to calling a property.
Examples:
var strLen1 := length("abc"); // 3
var strLen2 := length(default(String)); // 0
var myArray : array of Integer;
var arrLen1 := length(myArray); // 0
myArray := [1, 2, 3];
var arrLen2 := length(myArray); // 3
var strLen1 = length("abc"); // 3
var strLen2 = length(default(String)); // 0
int[] myArray;
var arrLen1 = length(myArray); // 0
myArray = [1, 2, 3];
var arrLen2 = length(myArray); // 3
let strLen1 = length("abc") // 3
let strLen2 = length(default(String)) // 0
var myArray: [Integer]?
let arrLen1 = length(myArray) // 0
myArray = [1, 2, 3]
let arrLen2 = length(myArray) // 3
var strLen1 = length("abc"); // 3
var strLen2 = length(default(String)); // 0
int[] myArray;
var arrLen1 = length(myArray); // 0
myArray = [1, 2, 3];
var arrLen2 = length(myArray); // 3