我想将变量中的数据保存到XML文件中,并在重新启动程序后将其加载



我想将变量保存在XML文件中,如果我再次启动程序,我想将保存的数据加载到程序/变量中。我怎么能做到呢?在创建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("nnHow 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:UserstobiaDesktopNeuer Ordnerfixcosts_january.xml");
}
}
}

}

在分配变量之前创建XDocument。将new XDocument(...所在行移到调用Save()之前。

相关内容

  • 没有找到相关文章

最新更新