C
C#2y ago
Chris TCC

retrieving dictionary value

I've got a dictionary that stores a string key and a bool as it's value. How do I retrieve the bool value for use in an if-statement? Currently I'm doing this:
bool tempLurkStatus;
if(lurkStatus.TryGetValue(userName, out tempLurkStatus) && tempLurkStatus == true)
bool tempLurkStatus;
if(lurkStatus.TryGetValue(userName, out tempLurkStatus) && tempLurkStatus == true)
11 Replies
Chris TCC
Chris TCCOP2y ago
I think if I remove the tempLurkStatus == true and just put the TryGetValue alone, it'll return true if the value exists, but not if the bool is true, right?
ero
ero2y ago
yup
Chris TCC
Chris TCCOP2y ago
so how would I check if the bool is true? do I have to retrieve the bool and store it in a temporary var outside the if statement? or can I do it inside somehow?
sibber
sibber2y ago
you can inline it your ide should suggest that
Chris TCC
Chris TCCOP2y ago
stored bool is true -> pass stored bool is false -> fail key doesn't exist -> fail this is what I want the if statement to check
ero
ero2y ago
that's what you're doing, yup
Chris TCC
Chris TCCOP2y ago
doesn't seem to work though if the code is correct, then I guess I'll have to check why it's not working... alright just to confirm - the code I put up there is correct right?
sibber
sibber2y ago
yes == true is redundant but yes
Chris TCC
Chris TCCOP2y ago
wait it is? I thought if I didn't add that, it'd just check if the key exists
sibber
sibber2y ago
myBool == true is the same as myBool
Chris TCC
Chris TCCOP2y ago
oh yeah. true.
Want results from more Discord servers?
Add your server