Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I used a dictionary in my code
C#
Dictionary<Int32, Dictionary<Int32, List<Int32>>> Staffs = new  Dictionary<int, Dictionary<int, List<int>>>();

then add keys
C#
if (!Staffs.Keys.Contains(staff))
               {
                   Staffs.Add(staff, new Dictionary<int, List<int>>());
               }

               if (!Staffs[staff].Keys.Contains(triad))
               {
                   Staffs[staff].Add(triad, new List<int>());
               }

and then add some value
...
C#
if (staff == 1 && triad == 1)
                   {
                       triad1 = Staffs[1][1].ToArray(); Array.Sort(triad1);
                       mypoint.Add(newpoint);

                   }

...
NOW I want to remove some value from staff[1][1]
????????????????????????????????????????????????????????
please...

What I have tried:

I test Staffs[1][1].RemoveAt(value); but It didn't work
Posted
Updated 20-Jul-16 4:51am
Comments
F-ES Sitecore 20-Jul-16 10:42am    
You have a dictionary inside a dictionary. Do you want to remove from the main dictionary (Staffs), or a dictionary that is a value inside the Staffs dictionary?
hojatIzadi 20-Jul-16 10:43am    
yes a dictionary that is a value inside the Staffs dictionary
Philippe Mori 20-Jul-16 14:03pm    
Obviously, you should read official MSDN documentation before asking trivial questions.

C#
Dictionary<Int32, Dictionary<Int32, List<Int32>>> Staffs = new Dictionary<int, Dictionary<int, List<int>>>();

Dictionary<Int32, List<Int32>> staffsDataItem = new Dictionary<int, List<int>>();
staffsDataItem.Add(10, new List<int> {11, 12, 13});
Staffs.Add(1, staffsDataItem);

staffsDataItem = new Dictionary<int, List<int>>();
staffsDataItem.Add(20, new List<int> { 21, 22, 23 });
staffsDataItem.Add(200, new List<int> { 201, 202, 203 });
Staffs.Add(2, staffsDataItem);

staffsDataItem = new Dictionary<int, List<int>>();
staffsDataItem.Add(30, new List<int> { 31, 32, 33 });
Staffs.Add(3, staffsDataItem);

// delete the entire Staffs "3" item
Staffs.Remove(3);

// delete the "20" item from the Staffs "2" item

Staffs[2].Remove(20);
    Console.ReadLine();
}
 
Share this answer
 
Use the Dictionary(TKey, TValue).Remove Method (TKey) (System.Collections.Generic)[^]
In your case, that would be:
C#
Staffs[1].Remove(1);
 
Share this answer
 
Comments
hojatIzadi 20-Jul-16 11:06am    
thanks and sorry I want to remove an int value from the list that is Tvalue in inner dictionary
OriginalGriff 20-Jul-16 11:38am    
Ah! That just means a further index:

Staffs[1][1].Remove(listValue);

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