Populating a Three Dimensional Dictionary gives weird Results in C#
I am trying to fill my Three-Dimensional Dictionary inside of a Loop, where I iterate through the years, months and ItemCategories.
Dictionary<int,Dictionary<int, Dictionary<ItemCategories, List<ExpenseStatisticItem>>>> ExpenseItemsData
ExpenseItemsData[currentYear][currentMonth][category].Add(item);
While Debugging following is being called:
ExpenseItemsData[2016][3][ItemCategory.Food].Add("Bla");
Now somehow it doesn't put the Entry where I told him to, but instead it gets put in every Entry of the Dictionary where Category == Food. Somehow the Years and the Months get completely ignored.
What am I missing?
Here is the full code:
string currentDate = "";
int currentMonth = 0;
int currentYear = 0;
string fileName = "DynamischeAusgaben.txt";
var directory = new DirectoryInfo("C:/MeineDaten/FinanzProgramm/Statistik/");
var years = directory.GetDirectories();
foreach (var year in years)
{
currentYear = int.Parse(year.Name);
if (currentYear == 0)
{
continue;
}
directory = new DirectoryInfo(String.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/", currentYear));
var months = directory.GetDirectories();
foreach (var month in months)
{
currentMonth = int.Parse(month.Name);
if (currentMonth == 0)
{
continue;
}
int dayCount = DateTime.DaysInMonth(currentYear, currentMonth);
List<string> dayDates = new List<string>();
// Datums der verschiedenen Tage dieses Monats zusammenstellen
for (int i = 1; i < dayCount + 1; i++)
{
dayDates.Add(new DateTime(currentYear, currentMonth, i, 0, 0, 0).ToShortDateString());
}
string path = string.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/{1}/DynamischeAusgaben",
currentYear, currentMonth);
bool fileExists = File.Exists(Path.Combine(path, fileName));
if (!fileExists)
{
continue;
}
string data = "";
using (StreamReader sr = new StreamReader(Path.Combine(path, fileName)))
{
data = sr.ReadToEnd();
data = data.Replace(System.Environment.NewLine, "");
}
foreach (var date in dayDates)
{
// Wenn das Datum nicht in der Datei enthalten ist, geh weiter.
if (!data.Contains(date))
{
continue;
}
string days = data.Split(';');
for (int i = 0; i < days.Length; i++)
{
// Leere Zeile ignorieren
if (days[i] == "")
{
continue;
}
string dayAndCategories = days[i].Split('<');
string dayString = dayAndCategories[0];
for (int j = 1; j < dayAndCategories.Length; j++)
{
string categoryAndItems = dayAndCategories[j].Split('|');
ItemCategories category = (ItemCategories)Enum.Parse(typeof(ItemCategories), categoryAndItems[0]);
decimal total = decimal.Parse(categoryAndItems[1]);
string itemsAndNothing = categoryAndItems[2].Split('>');
for (int k = 0; k < itemsAndNothing.Length; k++)
{
if (itemsAndNothing[k] == "")
{
continue;
}
string itemvalues = itemsAndNothing[1].Split('#');
ExpenseStatisticItem item = new ExpenseStatisticItem
{
Name = itemvalues[0],
Total = decimal.Parse(itemvalues[1]),
Count = int.Parse(itemvalues[2])
};
bool matchFound = false;
int matchIndex = 0;
// Ermitteln ob es schon ein Item mit diesem Namen in diesem Monat und Kategorie gibt
for (int l = 0; l < Global.ExpenseItemsData[currentYear][currentMonth][category].Count; l++)
{
ExpenseStatisticItem itemToCompare = Global.ExpenseItemsData[currentYear][currentMonth][category][l];
if (itemToCompare.Name == item.Name)
{
matchFound = true;
matchIndex = l;
}
}
// Wenn es schon ein Item gibt, dann fasse die Items zusammen
if (matchFound)
{
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Count += item.Count;
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Total += item.Total;
}
// Ansonsten erstelle einen neuen Eintrag
else
{
Global.ExpenseItemsData[currentYear][currentMonth][category].Add(item);
}
}
}
}
}
}
}
c# dictionary
|
show 1 more comment
I am trying to fill my Three-Dimensional Dictionary inside of a Loop, where I iterate through the years, months and ItemCategories.
Dictionary<int,Dictionary<int, Dictionary<ItemCategories, List<ExpenseStatisticItem>>>> ExpenseItemsData
ExpenseItemsData[currentYear][currentMonth][category].Add(item);
While Debugging following is being called:
ExpenseItemsData[2016][3][ItemCategory.Food].Add("Bla");
Now somehow it doesn't put the Entry where I told him to, but instead it gets put in every Entry of the Dictionary where Category == Food. Somehow the Years and the Months get completely ignored.
What am I missing?
Here is the full code:
string currentDate = "";
int currentMonth = 0;
int currentYear = 0;
string fileName = "DynamischeAusgaben.txt";
var directory = new DirectoryInfo("C:/MeineDaten/FinanzProgramm/Statistik/");
var years = directory.GetDirectories();
foreach (var year in years)
{
currentYear = int.Parse(year.Name);
if (currentYear == 0)
{
continue;
}
directory = new DirectoryInfo(String.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/", currentYear));
var months = directory.GetDirectories();
foreach (var month in months)
{
currentMonth = int.Parse(month.Name);
if (currentMonth == 0)
{
continue;
}
int dayCount = DateTime.DaysInMonth(currentYear, currentMonth);
List<string> dayDates = new List<string>();
// Datums der verschiedenen Tage dieses Monats zusammenstellen
for (int i = 1; i < dayCount + 1; i++)
{
dayDates.Add(new DateTime(currentYear, currentMonth, i, 0, 0, 0).ToShortDateString());
}
string path = string.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/{1}/DynamischeAusgaben",
currentYear, currentMonth);
bool fileExists = File.Exists(Path.Combine(path, fileName));
if (!fileExists)
{
continue;
}
string data = "";
using (StreamReader sr = new StreamReader(Path.Combine(path, fileName)))
{
data = sr.ReadToEnd();
data = data.Replace(System.Environment.NewLine, "");
}
foreach (var date in dayDates)
{
// Wenn das Datum nicht in der Datei enthalten ist, geh weiter.
if (!data.Contains(date))
{
continue;
}
string days = data.Split(';');
for (int i = 0; i < days.Length; i++)
{
// Leere Zeile ignorieren
if (days[i] == "")
{
continue;
}
string dayAndCategories = days[i].Split('<');
string dayString = dayAndCategories[0];
for (int j = 1; j < dayAndCategories.Length; j++)
{
string categoryAndItems = dayAndCategories[j].Split('|');
ItemCategories category = (ItemCategories)Enum.Parse(typeof(ItemCategories), categoryAndItems[0]);
decimal total = decimal.Parse(categoryAndItems[1]);
string itemsAndNothing = categoryAndItems[2].Split('>');
for (int k = 0; k < itemsAndNothing.Length; k++)
{
if (itemsAndNothing[k] == "")
{
continue;
}
string itemvalues = itemsAndNothing[1].Split('#');
ExpenseStatisticItem item = new ExpenseStatisticItem
{
Name = itemvalues[0],
Total = decimal.Parse(itemvalues[1]),
Count = int.Parse(itemvalues[2])
};
bool matchFound = false;
int matchIndex = 0;
// Ermitteln ob es schon ein Item mit diesem Namen in diesem Monat und Kategorie gibt
for (int l = 0; l < Global.ExpenseItemsData[currentYear][currentMonth][category].Count; l++)
{
ExpenseStatisticItem itemToCompare = Global.ExpenseItemsData[currentYear][currentMonth][category][l];
if (itemToCompare.Name == item.Name)
{
matchFound = true;
matchIndex = l;
}
}
// Wenn es schon ein Item gibt, dann fasse die Items zusammen
if (matchFound)
{
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Count += item.Count;
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Total += item.Total;
}
// Ansonsten erstelle einen neuen Eintrag
else
{
Global.ExpenseItemsData[currentYear][currentMonth][category].Add(item);
}
}
}
}
}
}
}
c# dictionary
Please tag your question with a programming language, and please provide more code so we can determine where the issue is.
– Robin Green
Nov 24 '18 at 13:30
can you add the loop you wrote, and I would advice to create a structure or class instead of using what you call a three dimensiona Dictionary...
– Cedric Dumont
Nov 24 '18 at 14:34
How do you create the dictionary?
– Luaan
Nov 24 '18 at 14:52
2
Likely you have reused the sameList
object in each case instead of creating a new one so they all point to the same list for a given food type.
– Ian Mercer
Nov 24 '18 at 14:58
BTW, unless your access pattern is always Y>M>C, this nested dictionary approach might not be a good one. A simpleList<ExpenseItem>
and LINQ Where clauses to filter by year, month or food type or any combination thereof would be easier to code, more readable and more flexible.
– Ian Mercer
Nov 24 '18 at 15:02
|
show 1 more comment
I am trying to fill my Three-Dimensional Dictionary inside of a Loop, where I iterate through the years, months and ItemCategories.
Dictionary<int,Dictionary<int, Dictionary<ItemCategories, List<ExpenseStatisticItem>>>> ExpenseItemsData
ExpenseItemsData[currentYear][currentMonth][category].Add(item);
While Debugging following is being called:
ExpenseItemsData[2016][3][ItemCategory.Food].Add("Bla");
Now somehow it doesn't put the Entry where I told him to, but instead it gets put in every Entry of the Dictionary where Category == Food. Somehow the Years and the Months get completely ignored.
What am I missing?
Here is the full code:
string currentDate = "";
int currentMonth = 0;
int currentYear = 0;
string fileName = "DynamischeAusgaben.txt";
var directory = new DirectoryInfo("C:/MeineDaten/FinanzProgramm/Statistik/");
var years = directory.GetDirectories();
foreach (var year in years)
{
currentYear = int.Parse(year.Name);
if (currentYear == 0)
{
continue;
}
directory = new DirectoryInfo(String.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/", currentYear));
var months = directory.GetDirectories();
foreach (var month in months)
{
currentMonth = int.Parse(month.Name);
if (currentMonth == 0)
{
continue;
}
int dayCount = DateTime.DaysInMonth(currentYear, currentMonth);
List<string> dayDates = new List<string>();
// Datums der verschiedenen Tage dieses Monats zusammenstellen
for (int i = 1; i < dayCount + 1; i++)
{
dayDates.Add(new DateTime(currentYear, currentMonth, i, 0, 0, 0).ToShortDateString());
}
string path = string.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/{1}/DynamischeAusgaben",
currentYear, currentMonth);
bool fileExists = File.Exists(Path.Combine(path, fileName));
if (!fileExists)
{
continue;
}
string data = "";
using (StreamReader sr = new StreamReader(Path.Combine(path, fileName)))
{
data = sr.ReadToEnd();
data = data.Replace(System.Environment.NewLine, "");
}
foreach (var date in dayDates)
{
// Wenn das Datum nicht in der Datei enthalten ist, geh weiter.
if (!data.Contains(date))
{
continue;
}
string days = data.Split(';');
for (int i = 0; i < days.Length; i++)
{
// Leere Zeile ignorieren
if (days[i] == "")
{
continue;
}
string dayAndCategories = days[i].Split('<');
string dayString = dayAndCategories[0];
for (int j = 1; j < dayAndCategories.Length; j++)
{
string categoryAndItems = dayAndCategories[j].Split('|');
ItemCategories category = (ItemCategories)Enum.Parse(typeof(ItemCategories), categoryAndItems[0]);
decimal total = decimal.Parse(categoryAndItems[1]);
string itemsAndNothing = categoryAndItems[2].Split('>');
for (int k = 0; k < itemsAndNothing.Length; k++)
{
if (itemsAndNothing[k] == "")
{
continue;
}
string itemvalues = itemsAndNothing[1].Split('#');
ExpenseStatisticItem item = new ExpenseStatisticItem
{
Name = itemvalues[0],
Total = decimal.Parse(itemvalues[1]),
Count = int.Parse(itemvalues[2])
};
bool matchFound = false;
int matchIndex = 0;
// Ermitteln ob es schon ein Item mit diesem Namen in diesem Monat und Kategorie gibt
for (int l = 0; l < Global.ExpenseItemsData[currentYear][currentMonth][category].Count; l++)
{
ExpenseStatisticItem itemToCompare = Global.ExpenseItemsData[currentYear][currentMonth][category][l];
if (itemToCompare.Name == item.Name)
{
matchFound = true;
matchIndex = l;
}
}
// Wenn es schon ein Item gibt, dann fasse die Items zusammen
if (matchFound)
{
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Count += item.Count;
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Total += item.Total;
}
// Ansonsten erstelle einen neuen Eintrag
else
{
Global.ExpenseItemsData[currentYear][currentMonth][category].Add(item);
}
}
}
}
}
}
}
c# dictionary
I am trying to fill my Three-Dimensional Dictionary inside of a Loop, where I iterate through the years, months and ItemCategories.
Dictionary<int,Dictionary<int, Dictionary<ItemCategories, List<ExpenseStatisticItem>>>> ExpenseItemsData
ExpenseItemsData[currentYear][currentMonth][category].Add(item);
While Debugging following is being called:
ExpenseItemsData[2016][3][ItemCategory.Food].Add("Bla");
Now somehow it doesn't put the Entry where I told him to, but instead it gets put in every Entry of the Dictionary where Category == Food. Somehow the Years and the Months get completely ignored.
What am I missing?
Here is the full code:
string currentDate = "";
int currentMonth = 0;
int currentYear = 0;
string fileName = "DynamischeAusgaben.txt";
var directory = new DirectoryInfo("C:/MeineDaten/FinanzProgramm/Statistik/");
var years = directory.GetDirectories();
foreach (var year in years)
{
currentYear = int.Parse(year.Name);
if (currentYear == 0)
{
continue;
}
directory = new DirectoryInfo(String.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/", currentYear));
var months = directory.GetDirectories();
foreach (var month in months)
{
currentMonth = int.Parse(month.Name);
if (currentMonth == 0)
{
continue;
}
int dayCount = DateTime.DaysInMonth(currentYear, currentMonth);
List<string> dayDates = new List<string>();
// Datums der verschiedenen Tage dieses Monats zusammenstellen
for (int i = 1; i < dayCount + 1; i++)
{
dayDates.Add(new DateTime(currentYear, currentMonth, i, 0, 0, 0).ToShortDateString());
}
string path = string.Format("C:/MeineDaten/FinanzProgramm/Statistik/{0}/{1}/DynamischeAusgaben",
currentYear, currentMonth);
bool fileExists = File.Exists(Path.Combine(path, fileName));
if (!fileExists)
{
continue;
}
string data = "";
using (StreamReader sr = new StreamReader(Path.Combine(path, fileName)))
{
data = sr.ReadToEnd();
data = data.Replace(System.Environment.NewLine, "");
}
foreach (var date in dayDates)
{
// Wenn das Datum nicht in der Datei enthalten ist, geh weiter.
if (!data.Contains(date))
{
continue;
}
string days = data.Split(';');
for (int i = 0; i < days.Length; i++)
{
// Leere Zeile ignorieren
if (days[i] == "")
{
continue;
}
string dayAndCategories = days[i].Split('<');
string dayString = dayAndCategories[0];
for (int j = 1; j < dayAndCategories.Length; j++)
{
string categoryAndItems = dayAndCategories[j].Split('|');
ItemCategories category = (ItemCategories)Enum.Parse(typeof(ItemCategories), categoryAndItems[0]);
decimal total = decimal.Parse(categoryAndItems[1]);
string itemsAndNothing = categoryAndItems[2].Split('>');
for (int k = 0; k < itemsAndNothing.Length; k++)
{
if (itemsAndNothing[k] == "")
{
continue;
}
string itemvalues = itemsAndNothing[1].Split('#');
ExpenseStatisticItem item = new ExpenseStatisticItem
{
Name = itemvalues[0],
Total = decimal.Parse(itemvalues[1]),
Count = int.Parse(itemvalues[2])
};
bool matchFound = false;
int matchIndex = 0;
// Ermitteln ob es schon ein Item mit diesem Namen in diesem Monat und Kategorie gibt
for (int l = 0; l < Global.ExpenseItemsData[currentYear][currentMonth][category].Count; l++)
{
ExpenseStatisticItem itemToCompare = Global.ExpenseItemsData[currentYear][currentMonth][category][l];
if (itemToCompare.Name == item.Name)
{
matchFound = true;
matchIndex = l;
}
}
// Wenn es schon ein Item gibt, dann fasse die Items zusammen
if (matchFound)
{
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Count += item.Count;
Global.ExpenseItemsData[currentYear][currentMonth][category][matchIndex].Total += item.Total;
}
// Ansonsten erstelle einen neuen Eintrag
else
{
Global.ExpenseItemsData[currentYear][currentMonth][category].Add(item);
}
}
}
}
}
}
}
c# dictionary
c# dictionary
edited Nov 25 '18 at 16:09
user3086972
asked Nov 24 '18 at 13:19
user3086972user3086972
255
255
Please tag your question with a programming language, and please provide more code so we can determine where the issue is.
– Robin Green
Nov 24 '18 at 13:30
can you add the loop you wrote, and I would advice to create a structure or class instead of using what you call a three dimensiona Dictionary...
– Cedric Dumont
Nov 24 '18 at 14:34
How do you create the dictionary?
– Luaan
Nov 24 '18 at 14:52
2
Likely you have reused the sameList
object in each case instead of creating a new one so they all point to the same list for a given food type.
– Ian Mercer
Nov 24 '18 at 14:58
BTW, unless your access pattern is always Y>M>C, this nested dictionary approach might not be a good one. A simpleList<ExpenseItem>
and LINQ Where clauses to filter by year, month or food type or any combination thereof would be easier to code, more readable and more flexible.
– Ian Mercer
Nov 24 '18 at 15:02
|
show 1 more comment
Please tag your question with a programming language, and please provide more code so we can determine where the issue is.
– Robin Green
Nov 24 '18 at 13:30
can you add the loop you wrote, and I would advice to create a structure or class instead of using what you call a three dimensiona Dictionary...
– Cedric Dumont
Nov 24 '18 at 14:34
How do you create the dictionary?
– Luaan
Nov 24 '18 at 14:52
2
Likely you have reused the sameList
object in each case instead of creating a new one so they all point to the same list for a given food type.
– Ian Mercer
Nov 24 '18 at 14:58
BTW, unless your access pattern is always Y>M>C, this nested dictionary approach might not be a good one. A simpleList<ExpenseItem>
and LINQ Where clauses to filter by year, month or food type or any combination thereof would be easier to code, more readable and more flexible.
– Ian Mercer
Nov 24 '18 at 15:02
Please tag your question with a programming language, and please provide more code so we can determine where the issue is.
– Robin Green
Nov 24 '18 at 13:30
Please tag your question with a programming language, and please provide more code so we can determine where the issue is.
– Robin Green
Nov 24 '18 at 13:30
can you add the loop you wrote, and I would advice to create a structure or class instead of using what you call a three dimensiona Dictionary...
– Cedric Dumont
Nov 24 '18 at 14:34
can you add the loop you wrote, and I would advice to create a structure or class instead of using what you call a three dimensiona Dictionary...
– Cedric Dumont
Nov 24 '18 at 14:34
How do you create the dictionary?
– Luaan
Nov 24 '18 at 14:52
How do you create the dictionary?
– Luaan
Nov 24 '18 at 14:52
2
2
Likely you have reused the same
List
object in each case instead of creating a new one so they all point to the same list for a given food type.– Ian Mercer
Nov 24 '18 at 14:58
Likely you have reused the same
List
object in each case instead of creating a new one so they all point to the same list for a given food type.– Ian Mercer
Nov 24 '18 at 14:58
BTW, unless your access pattern is always Y>M>C, this nested dictionary approach might not be a good one. A simple
List<ExpenseItem>
and LINQ Where clauses to filter by year, month or food type or any combination thereof would be easier to code, more readable and more flexible.– Ian Mercer
Nov 24 '18 at 15:02
BTW, unless your access pattern is always Y>M>C, this nested dictionary approach might not be a good one. A simple
List<ExpenseItem>
and LINQ Where clauses to filter by year, month or food type or any combination thereof would be easier to code, more readable and more flexible.– Ian Mercer
Nov 24 '18 at 15:02
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458548%2fpopulating-a-three-dimensional-dictionary-gives-weird-results-in-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458548%2fpopulating-a-three-dimensional-dictionary-gives-weird-results-in-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please tag your question with a programming language, and please provide more code so we can determine where the issue is.
– Robin Green
Nov 24 '18 at 13:30
can you add the loop you wrote, and I would advice to create a structure or class instead of using what you call a three dimensiona Dictionary...
– Cedric Dumont
Nov 24 '18 at 14:34
How do you create the dictionary?
– Luaan
Nov 24 '18 at 14:52
2
Likely you have reused the same
List
object in each case instead of creating a new one so they all point to the same list for a given food type.– Ian Mercer
Nov 24 '18 at 14:58
BTW, unless your access pattern is always Y>M>C, this nested dictionary approach might not be a good one. A simple
List<ExpenseItem>
and LINQ Where clauses to filter by year, month or food type or any combination thereof would be easier to code, more readable and more flexible.– Ian Mercer
Nov 24 '18 at 15:02