About 37,100 results
Open links in new tab
  1. Proper way to initialize a C# dictionary with values

    private readonly Dictionary<string, XlFileFormat> FILE_TYPE_DICT = new Dictionary<string, XlFileFormat> { {"csv", XlFileFormat.xlCSV}, {"html", XlFileFormat.xlHtml} }; There is a red line …

  2. c# - How to iterate over a dictionary? - Stack Overflow

    I've seen a few different ways to iterate over a dictionary in C#. Is there a standard way?

  3. How to add multiple values for single key in a Dictionary?

    Feb 13, 2025 · Dictionary<string, List<string>> dictionary = new(); I want to add string values to the list of string for a given single key. If the key doesn't already exists then I have to add a …

  4. How to update the value stored in Dictionary in C#?

    Aug 7, 2009 · How to update value for a specific key in a dictionary Dictionary&lt;string, int&gt;?

  5. Method to add new or update existing item in C# Dictionary

    Mar 19, 2024 · In some legacy code I have seen the following extension method to facilitate adding a new key-value item or updating an existing value: Method-1 (legacy code): public …

  6. c# - A difference in style: IDictionary vs Dictionary - Stack Overflow

    Oct 15, 2015 · IDictionary<string> dictionary = new Dictionary<string>(); And now dictionary invokes the methods and properties of Dictionary<string>. In the future the databases has …

  7. c# - .NET Dictionary: get existing value or create and add new …

    I often find myself creating a Dictionary with a non-trivial value class (e.g. List), and then always writing the same code pattern when filling in data. For example: var dict = new Dictionary&lt;

  8. c# - Multi Value Dictionary? - Stack Overflow

    Personally I don't like the idea of inheriting from Dictionary<TKey, List<TValue>> (or similar) as I think it exposes too much (calling code could add/remove from the List<T> value directly, for …

  9. How to add multiple values to Dictionary in C#? - Stack Overflow

    What is the best way to add multiple values to a Dictionary if I don't want to call &quot;.Add()&quot; multiple times. Edit: I want to fill it after initiation! there are already some …

  10. dictionary - Merging dictionaries in C# - Stack Overflow

    What's the best way to merge 2 or more dictionaries (Dictionary&lt;TKey, TValue&gt;) in C#? (3.0 features like LINQ are fine). I'm thinking of a method signature along the lines of: public static