57 questions
0 votes
3 answers
753 views
Which is more efficient Dictionary.TryGetValue or List.Any
I have a case where I have to find out if element belongs to a list or not in loop. The straight forward way to do this is to call the Any method of the list, like this public class Person { ...
0 votes
2 answers
519 views
RouteValues.TryGetValue gives "Local variable 'X' might not be initialized before accessing" error even if the result is true?
if (!this._contextAccessor.HttpContext?.Request.RouteValues.TryGetValue("requiredId", out var idRouteParam) ?? true) return Task.CompletedTask; var id = (int)idRouteParam; I ...
2 votes
1 answer
7k views
Get the value of a specific key in a dictionary in C#
I have a dictionary like this: Dictionary<string, List<string>> mydict = new Dictionary<string, List<string>>(); I have tried: foreach(var value in mydict.Keys) { List<...
0 votes
1 answer
480 views
Improve performance of TryGetValue
I am creating an Excel file using Open XML SDK. In this process, I have a scenario like below. I need to add data into a Dictionary<uint, string> if key is not exists. For that I am using below ...
1 vote
2 answers
3k views
TryGetValue on a null dictionary
I am trying to use TryGetValue on a Dictionary as usual, like this code below: Response.Context.Skills[MAIN_SKILL].UserDefined.TryGetValue("action", out var actionObj) My problem is the ...
1 vote
2 answers
926 views
Why is TryGetValue on a Dictionary who's key is also a dictionary returning Null?
Goal: get a value from a dictionary. Said value has a dictionary as a key. What I'm doing: I'm creating a second dictionary that has the exact same values as the key whose value I'm trying to get. ...
0 votes
0 answers
31 views
Overriding GetHashCode with randomly missing properties [duplicate]
I have dictionary based on a custom class. I am facing issues with overriding the GetHashCode() while inheriting IEquatable interface. My class object has three properties: Id1 (string) Id2 (string) ...
0 votes
1 answer
37 views
Why is Dictionary<TKey,TValue>.TryGetValue(TKey, TValue) always returning true?
I'm trying to use Dictionary.TryGetValue() to search a dictionary for a username and password hash, if it matches authenticate the user, if not do something else. The problem I'm having is that ...
0 votes
2 answers
157 views
Retrieve a value from an Enum in Java
Below are two classes Deck and Card. these are being used for a blackjack game and therefore i am trying to get the values of the cards. the values are currently stored in an enum, however i cannot ...
0 votes
0 answers
272 views
C# Extension static class fails when reading Properties with TryGetValue
I have the below Extension (not mine, borrowed for my implementation, but altered a bit) and I am wondering why is the TryGetValue below failing, despite the fact the the pair (string, object - well, ...
-4 votes
1 answer
1k views
How can I get value from IDictionary ? When I try I got "does not contain method TryGetValue" error
I have an IDictionary object , my question is how I can read data by key? It looks easier question but there is no method (even similiar one is not found) like TryGetValue . Only Contains method ...
1 vote
1 answer
1k views
TryGetValue gives incorrect result
I am trying to get the value from Dictionary(JSON deserialized) and parse it as long. When I quick viewed the variable I found there is no "M" as part of the out parameter a s given below But when I ...
-1 votes
2 answers
3k views
How do I get value from span and assign it to a php variable? [closed]
How can I take the value of: <span name="MinPrice" class="irs-from">0</span> <span name="MaxPrice" class="irs-to">0</span> And assign them to PHP variables: $MinPrice $...
1 vote
1 answer
266 views
Resharper Refactor pattern for TryGetValue in Dictionary
The most cumbersome piece of syntax I need to continually write is lazily initializing a container in a dictionary like: ContainerRecord value; if(!_dictionary.TryGetValue(key,out value)) { value =...
0 votes
2 answers
634 views
popup Div td get value using Jquery
Below is the div which i am trying to show in a popup. How do i get the td value from the popup. When trying to call the popupClick(). it returns undefined. I have attached the code below. Thanks in ...