It really does seem like you’re overcomplicating this issue.
You can just use the indexer ([]
) of the Dictionary
class along with the .ContainsKey()
method.
If you use something like this:
string value; if (myDict.ContainsKey(key)) { value = myDict[key]; } else { Console.WriteLine("Key Not Present"); return; }
You should achieve the effect that you want.
Related Posts:
- Group by in LINQ
- Join/Where with LINQ and Lambda
- What is C# equivalent of
- LINQ’s Distinct() on a particular property
- Sequence contains no elements?
- LEFT OUTER JOIN in LINQ
- ToList().ForEach in Linq
- Extension methods must be defined in a non-generic static class
- What is the best way to iterate over a dictionary?
- Proper way to initialize a C# dictionary with values
- Proper Linq where clauses
- Extension methods must be defined in a non-generic static class
- Get dictionary value by key
- Select distinct using linq
- Collection was modified; enumeration operation may not execute
- Convert Linq Query Result to Dictionary
- IEnumerable vs List – What to Use? How do they work?
- Sequence contains no matching element
- How do you sort a dictionary by value?
- How to update the value stored in Dictionary in C#?
- Cannot implicitly convert type ‘System.Collections.Generic.List< >‘ to ‘System.Collections.Generic.IList< >‘
- Get dictionary key by value
- Linq select objects in list where exists IN (A,B,C)
- How do I concatenate two arrays in C#?
- Convert SQL to LINQ Query
- C# Convert List
to Dictionary - Sequence contains more than one element
- Quickest way to compare two generic lists for differences
- LINQ query on a DataTable
- Using .Select and .Where in a single LINQ statement
- C# Dictionary get item by index
- Linq: GroupBy, Sum and Count
- Convert HTML to PDF in .NET
- C# HttpClient An existing connection was forcibly closed by the remote host
- IOException: The process cannot access the file ‘file path’ because it is being used by another process
- Error : Index was outside the bounds of the array.
- No connection could be made because the target machine actively refused it?
- What does a lock statement do under the hood?
- What are the benefits to marking a field as `readonly` in C#?
- ASP.NET 5 MVC: unable to connect to web server ‘IIS Express’
- Why is this code throwing an InvalidOperationException?
- How to add a default Default.aspx to a ASP.NET Web Application Project?
- Regex for numbers only
- C# equivalent of C++ vector, with contiguous memory?
- Access to the path is denied
- What does question mark and dot operator ?. mean in C# 6.0?
- How to jump in Unity 3d?
- Invalid URI: The format of the URI could not be determined
- Unity “The associated script can not be loaded” and “Win32Exception: The system cannot find the file specified”
- How to round up the result of integer division?
- Process exists with ExitCode 255
- The data types text and varchar are incompatible in the equal to operator in C#
- Name does not exist in the current context
- Read and parse a Json File in C#
- Passing just a type as a parameter in C#
- How to declare session variable in C#?
- Cannot open database “test” requested by the login. The login failed. Login failed for user ‘xyz\ASPNET’
- Writing data into CSV file in C#
- System.Data.SqlClient.SqlException: Login failed for user
- How to post JSON to a server using C#?
- C# Print list of string array
- finding the maximum length of lists in c#
- “A project with an Output type of Class Library cannot be started directly”
- Creating a comma separated list from IList
or IEnumerable - Randomize a List
- “A project with an Output type of Class Library cannot be started directly”
- Conversion of a datetime2 data type to a datetime data type results out-of-range value
- JSON.NET Error Self referencing loop detected for type
- entity object cannot be referenced by multiple instances of IEntityChangeTracker. while adding related objects to entity in Entity Framework 4.1
- What does ModelState.IsValid do?
- When to use an Enum vs Struct
- How to make a simple popup box in Visual C#?
- windows could not start service on local computer error 5 access is denied
- ‘An exception occurred during a WebClient request” while using C# ASP.NET
- Destroy an object in C#
- Adding a newline into a string in C#
- How to format a string as a telephone number in C#
- How can we generate getters and setters in Visual Studio?
- .NET String.Format() to add commas in thousands place for a number
- Fastest way to generate a random boolean
- need implement C# Counter
- Invalid attempt to read when no data is present
- How to enable assembly bind failure logging (Fusion) in .NET
- How to make inline functions in C#
- What is the simplest regular expression to validate emails to not accept them blindly?
- The provider did not return a ProviderManifestToken string Entity Framework
- Why is HttpContext.Current null?
- Getting selected value of a combobox
- How do I clone a generic list in C#?
- Is there a way to toggle a boolean variable in C#?
- Effectively use async/await with ASP.NET Web API
- A potentially dangerous Request.Path value was detected from the client (*)
- Get single listView SelectedItem
- .NET Core vs Mono
- Convert JSON String to JSON Object c#
- Add item to Listview control
- Windows service start failure: Cannot start service from the command line or debugger [duplicate]
- Displaying DateTime picker instead of Date picker in ASP .NET MVC 5.1/HTML 5 specific
- How to enumerate an enum
- How to connect to database from Unity