[英]I want to save data from variables into a XML file and coad it after restart of the programm
我想将变量保存在 XML 文件中,如果我再次启动程序,我想将保存的数据加载到程序/变量中。 我怎么能这样做? ATM XML 已创建,但变量的数据始终以“0,0”保存。
double fixcosts = 0.0;
double costs = 0.0;
Maths math = new Maths();
int month = DateTime.Today.Month;
if (month == 1)
{
XDocument January_costs_categories = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement("CostsCategories",
new XElement("Fixcosts", fixcosts + " Euro"),
new XElement("Costs", costs + " Euro")));
Console.WriteLine("\n JANUARY COSTS \n");
Console.WriteLine($"Fixcosts = {fixcosts}");
Console.WriteLine($"Costs = {costs}");
Console.WriteLine("\n\nHow much you wanna add?");
double howMuch = Convert.ToDouble(Console.ReadLine());
fixcosts = math.Addieren(fixcosts, howMuch);
Console.Clear();
Console.WriteLine("\n JANUARY COSTS \n");
Console.WriteLine($"Fixcosts = {fixcosts}");
Console.WriteLine($"Costs = {costs}");
January_costs_categories.Save(@"C:\Users\tobia\Desktop\Neuer Ordner\fixcosts_january.xml");
}
}
}
}
您在分配变量之前创建了 XDocument。 将带有new XDocument(...
的行移至调用Save()
之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.