Re-using variables can be dangerous
-
Re-using variables can be dangerous. The following code had me baffled for hours. This code queries a dozen different XML files on the server, builds a response, and serves it to different dashboards.
fileName = "FinSummaryByMonth"; xmlFile = Server.MapPath("Data/" + DistrictNumber + "/" + sYearFolder + "/" + fileName + ".xml"); srcDoc = XDocument.Load(xmlFile); //linq to xml process 1...should build 13 rows with 12 elements...OK //append to the buildDoc and move on to the next section fileName = "MealSummaryByMonth"; srcDoc = XDocument.Load(xmlFile); //linq to xml process 1...should build 11 rows with 12 elements...WRONG! returning 13 rows!
Being a newbie to linq, I had assumed the mistake was in the query. 2 hours later, looking at the output, I realize that the rows in the problem section were identical to the rows in the previous section nevermind that the results should have been ints. :doh:
"Go forth into the source" - Neal Morse
-
Re-using variables can be dangerous. The following code had me baffled for hours. This code queries a dozen different XML files on the server, builds a response, and serves it to different dashboards.
fileName = "FinSummaryByMonth"; xmlFile = Server.MapPath("Data/" + DistrictNumber + "/" + sYearFolder + "/" + fileName + ".xml"); srcDoc = XDocument.Load(xmlFile); //linq to xml process 1...should build 13 rows with 12 elements...OK //append to the buildDoc and move on to the next section fileName = "MealSummaryByMonth"; srcDoc = XDocument.Load(xmlFile); //linq to xml process 1...should build 11 rows with 12 elements...WRONG! returning 13 rows!
Being a newbie to linq, I had assumed the mistake was in the query. 2 hours later, looking at the output, I realize that the rows in the problem section were identical to the rows in the previous section nevermind that the results should have been ints. :doh:
"Go forth into the source" - Neal Morse
"Omit needless local variables." -- Strunk... had he taught programming Or, better, write a method and eliminate the repetitive code.
You'll never get very far if all you do is follow instructions.
-
"Omit needless local variables." -- Strunk... had he taught programming Or, better, write a method and eliminate the repetitive code.
You'll never get very far if all you do is follow instructions.
PIEBALDconsult wrote:
Or, better, write a method and eliminate the repetitive code.
This.
-
PIEBALDconsult wrote:
Or, better, write a method and eliminate the repetitive code.
This.