List.SingleOrDefault
If the list contains only one item, the function will return that item. If the list is empty, the function will return null unless a default value is specified. If the list contains multiple items, th...
If the list contains only one item, the function will return that item. If the list is empty, the function will return null unless a default value is specified. If the list contains multiple items, the function will return an error.
Example 1
Locate the sole value in the list {1}.
SyntaxPower Query MList.SingleOrDefault({1})
Result1
Example 2
Locate the sole value in an empty list {}.
SyntaxPower Query MList.SingleOrDefault({})
Resultnull
Example 3
Locate the sole value in an empty list {}. If empty, return -1.
SyntaxPower Query MList.SingleOrDefault({}, -1)
Result-1