LightningDB.LightningTransaction.TryGet C# (CSharp) Method

TryGet() public method

Tries to get a value by its key.
public TryGet ( LightningDatabase db, byte key, byte &value ) : bool
db LightningDatabase Database.
key byte Key byte array.
value byte Value byte array if exists.
return bool
        public bool TryGet(LightningDatabase db, byte[] key, out byte[] value)
        {
            if (db == null)
                throw new ArgumentNullException(nameof(db));

            return mdb_get(_handle, db.Handle(), key, out value) != MDB_NOTFOUND;
        }

Usage Example

        public static bool TryGetBy <TKey>(this LightningTransaction txn, LightningDatabase db, TKey key, out GetByOperation value)
        {
            byte[] valueBytes;

            var keyBytes = db.ToBytes(key);
            var result   = txn.TryGet(db, keyBytes, out valueBytes);

            value = result
                ? new GetByOperation(db, valueBytes)
                : null;

            return(result);
        }
All Usage Examples Of LightningDB.LightningTransaction::TryGet