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 TCC2y 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 TCC2y 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 TCC2y 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 TCC2y 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 TCC2y 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 TCC2y ago
oh yeah. true.
Want results from more Discord servers?
Add your server
More Posts
❔ How to migrate a virtual ICollection to a table on my SQL database?I have my model and it includes ICollections of different models that I would also like to save. I h❔ Default behavior of ComVisible attributeWhile updating a legacy .NET framework application to net6, I ran into a question where I was unable❔ Is there any overview of useful attributes and how to use them?E.g. [Obsolete] or for example where a method is allowed to be used and so on. Basically basic attri❔ Newtonsoft, count nested propertiesSome time ago I had a nice chat in here where we found a solution to a problem. Namely counting all list that holds 2 values eachI want to have a way to store a dynamic amount of data, where each entry holds a string and an int. ❔ How to close a process's handle?Hey folks, I'm trying to automate something that I've been doing manually through Process Explorer -❔ ObjectListView showing blank rowsHi all. I'm new to C# and making VSTO addins, please bare with me! I'm using the add-in control O❔ NullReferenceException Object reference not set to an instance of an object Billboard.UpdateHello, my name is Zorphix and I'm not so smart at C#. And I'm currently trying to add a billboard sc❔ Blazor Hosted - Client datatable with large datasetI have a table component (using MudBlazor) which accesses the server-side API endpoint and pulls (cu❔ How do I cycle through different observable collections within the same collection view?My current plan is to do something like: ``` List <ObservableCollection<TodoItem>> allTodoItems