Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeesh MenothRank #118 · 18.4K reputationPosted Dec 2, 2024, 2:04 AM EST
Hi,
What exactly do you need Kiran? As per your question, define a dictionary array as Jignesh already explained. Don't be confused with side arrays. It's an array that stores key-value pairs, similar to other collection types. Here, you can add different types of keys. In Jignesh's example, he added a key as a string and a value as an integer. Similarly, you can use different types for keys and values. You can also add a list of strings as a key. Everything depends on your business requirements.
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 30, 2024, 3:49 AM EST
Hello Kiran,
You can create Dictionary in side array,
using System; using System.Collections.Generic; public class Program { public static void Main() { // How to create array of dictionaries Dictionary[] arrayOfDictionaries = new Dictionary[3]; // Initialize dictionaries and add values in Array arrayOfDictionaries[0] = new Dictionary { { "apple", 1 }, { "banana", 2 } }; arrayOfDictionaries[1] = new Dictionary { { "car", 3 }, { "bus", 4 } }; arrayOfDictionaries[2] = new Dictionary { { "dog", 5 }, { "cat", 6 } }; // Access dictionary values in the array of dictionaries foreach (var dict in arrayOfDictionaries) { foreach (var kvp in dict) { Console.WriteLine($"{kvp.Key}: {kvp.Value}"); } } } }Kiran KumarRank #1,268 · 1.4K reputationPosted Dec 1, 2024, 2:54 AM EST
What is the meaning of side array can you explained in real time example?
I think other collection types also have key value pair storage right how this is different from other collection types
Kiran KumarRank #1,268 · 1.4K reputationPosted Dec 3, 2024, 12:46 AM EST
Hi Rajesh
Thanks for the response now I got it you mean to say Dictonay will store the different data types as key value pair I am trying to differentiate with hash table which has also the same feature right please correct me if I am wrong
Thanks for your response