How can I write the if statement to check if the keys are not in the dictionary
when I have a dictionary in a dictionary?
I started the if statement, but I do not know how to finish it.
Code is below.
Thanks,
arep
public static Dictionary<string, Dictionary<string, DebOop>> d = new Dictionary<string, Dictionary<string, DebOop>>();
public static void GetData(string memberNbr, string person, string group, string subGroup, string plancode, string date)
{
int year = (DateTime.ParseExact(date, "yyyy-MM-dd", CultureInfo.InvariantCulture)).Year;
//Is key not in dictionary
if (!d.ContainsKey(memberNbr))
{
UpdateData(memberNbr, person, group, subGroup, plancode, date);
}
}
Loading

VulpesRank #55 · 29.2K reputationPosted Aug 18, 2011, 11:59 AM EDT
A RepaskyRank #8,108 · 228 reputationPosted Aug 18, 2011, 12:09 PM EDT
My add is not working either. Here it is:
I do not know how this should be written. I have tried "(" also.
VulpesRank #55 · 29.2K reputationPosted Aug 18, 2011, 12:18 PM EDT
A RepaskyRank #8,108 · 228 reputationPosted Aug 18, 2011, 12:24 PM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 18, 2011, 12:35 PM EDT
public static void GetData(string memberNbr, string person, string group, string subGroup, string plancode, string date)
{
int year = (DateTime.ParseExact(date, "yyyy-MM-dd", CultureInfo.InvariantCulture)).Year;
//Is key not in dictionary
if (!d.ContainsKey(memberNbr)) // memberNbr isn't in outer dictionary
{
UpdateData(memberNbr, person, group, subGroup, plancode, date);
}
else // memberNbr is in outer dictionary
{
Dictionary
if(!dict.ContainsKey(year.ToString()) // but year isn't in inner dictionary for memberNbr outer key
{
UpdateData(memberNbr, person, group, subGroup, plancode, date);
}
}
}
A RepaskyRank #8,108 · 228 reputationPosted Aug 19, 2011, 10:56 AM EDT
getting is "<1>" for all the Console.Writeline's. I am using the KeyValuePair in a foreach.
Thanks,
Arep
A RepaskyRank #8,108 · 228 reputationPosted Aug 19, 2011, 12:00 PM EDT
foreach (KeyValuePairstring, Dictionarystring, record>> nestedpair in nested) { Console.WriteLine("A=" + "{0}", "{1}", nestedpair.Key, nestedpair.Value.ToString()); foreach (KeyValuePairstring, record> innerpair in inner) { Console.WriteLine("B=" + "{0}", "{1}", innerpair.Key, innerpair.Value.ToString()); } } foreach (var nestedpair in nested) { Console.WriteLine("C=" + "{0}", "{1}", nestedpair.Key, nestedpair.Value.ToString()); } The output is: A={1} B={1} A={1} B={1} C={1} C={1}VulpesRank #55 · 29.2K reputationPosted Aug 19, 2011, 12:21 PM EDT
I've also added the highlighted code to your record class:
A RepaskyRank #8,108 · 228 reputationPosted Aug 19, 2011, 1:27 PM EDT
Now two things. I still have to get this all working in the production class. And I do not understand why he had these two if statements. Everything is the same except for the year. I do not know if you could shed any light on this?
VulpesRank #55 · 29.2K reputationPosted Aug 19, 2011, 2:33 PM EDT
A RepaskyRank #8,108 · 228 reputationPosted Aug 20, 2011, 8:30 PM EDT
I will put the final result when I get the production program done. I will not get back to it until monday. I figure I should put the finally result when done. Also, I will probably have another question.
arep