Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Guy, please i Need your help. i learn today how to set value in my Dictionary but i don't really know how to get the different Value of them.

I insert data in a form of list and send it later in my database. the Problem is that i don't know how to get all this data out of my List. I read that it is possible with LinQ but i don't know. Please has somebody an idea? Hier is my Code.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Linq;

namespace Kommissionierung
{
    public class AuswahlListe
    {  
        Dictionary<string, Dictionary<string, string>> ChoiceList = new Dictionary<string, Dictionary<string, string>>();

        public void ChoiceAdd(Choice choice)
        {

            if (ChoiceList.ContainsKey(choice.MaterialsNummer))
            {       
                ChoiceList[choice.MaterialsNummer].Add(choice.CommandsNummer, choice.PersonalNr);
            }
            else
            {
                Dictionary<string, string> newinner = new Dictionary<string, string>();
                newinner.Add(choice.CommandsNummer, choice.PersonalNr);
                ChoiceList.Add(choice.MaterialsNummer, newinner);
            }

        }

        public void ChoiceListRemove(Choice choice)
        {
            if (ChoiceList.ContainsKey(choice.MaterialsNummer))
            {
                ChoiceList[choice.MaterialsNummer].Remove(choice.CommandsNummer);
            }
        }
        
    }
}

please Help me
Posted
Comments
[no name] 21-Jul-13 16:40pm    
You should start by reading the documentation, http://msdn.microsoft.com/en-us/library/bb347013.aspx
stefan from germany 21-Jul-13 17:07pm    
if i ask you it is because i don't understand how to make t. the Problem is not only to read but to understand. I read it but until yet it is not clear.

1 solution

The idea of the dictionary is to take some value by some unique key, with time complexity of O(1), using the mechanism based on hash table.
Please see:
http://en.wikipedia.org/wiki/Hash_table[^],
http://en.wikipedia.org/wiki/Big_O_notation[^],
http://en.wikipedia.org/wiki/Time_complexity[^].

You created a nested dictionary, which allows you to find a dictionary by a string key, and then a value in that dictionary through yet another key. For example:
C#
string FindByKeys(string dictionaryKey, string key) {
    try {
         return (ChoiceList[dictionaryKey])[key];
    } catch (KeyNotFoundException) {
         return null;
    } //exception
} //FindByKeys


I would say, the name ChoiceList is very confusing. This is not a list, this is a dictionary, a fundamentally different collection.

—SA
 
Share this answer
 
Comments
stefan from germany 21-Jul-13 17:42pm    
Thx Sergey the Link help me a lot.
Sergey Alexandrovich Kryukov 21-Jul-13 18:18pm    
My pleasure.
Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900