Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

idictionary

Convert List of KeyValuePair into IDictionary “C#”

April 19, 2023 by Tarik

Very, very simply with LINQ: IDictionary<string, string> dictionary = list.ToDictionary(pair => pair.Key, pair => pair.Value); Note that this will fail if there are any duplicate keys – I assume that’s okay?

Categories c# Tags c++, idictionary Leave a comment

Recreating a Dictionary from an IEnumerable

October 15, 2022 by Tarik

If you’re using .NET 3.5 or .NET 4, it’s easy to create the dictionary using LINQ: Dictionary<string, ArrayList> result = target.GetComponents() .ToDictionary(x => x.Key, x => x.Value); There’s no such thing as an IEnumerable<T1, T2> but a KeyValuePair<TKey, TValue> is fine.

Categories c# Tags c++, collections, dictionary, idictionary, ienumerable Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa