Created
November 21, 2018 12:08
-
-
Save JarkoDubbeldam/0caf0fc86715da0ff915ed8d6d877716 to your computer and use it in GitHub Desktop.
Dictionary.TryGetValue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool TryGetValue(TKey key, out TValue value) { // key is hier input, value is waar de output in komt. | |
int i = FindEntry(key); // Probeer de key te vinden. | |
if (i >= 0) { // Als die er is, succes! | |
value = entries[i].value; // Assign de waarde naar value, de output. | |
return true; // En return true om aan te geven dat het gelukt is. | |
} // Zo niet: | |
value = default(TValue); // De compiler vindt dat we per se hier iets in moeten vullen. We hebben de waarde niet gevonden, dus maar default. | |
return false; // Return false om aan te geven dat het niet gelukt is. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment