Skip to content

Modern Map TryGet

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Map › Map › TryGet

TryGet

Copies the value for a key into a variable; returns false, adding nothing, if absent.

Syntax

TryGet( k, byref out as V ) as boolean

Examples

#import "std/containers"
using containers

dim ages as Map( of ustring, integer )
ages.Put( "ada", 36 )

dim as integer got
if ages.TryGet( "ada", got ) then print got        '' 36

'' A miss leaves the output alone and does NOT insert -- unlike m[ k ]
got = -1
print ages.TryGet( "alan", got )    '' false
print got                            '' -1, untouched
print ages.Count                     '' 1 -- still just "ada"

Library: Map
Category: Map
Documented under: Members

Clone this wiki locally