嗨,我正在学习编程,但我遇到了一个问题。 我将用户输入保存到xml文件
private static void AddEntry(string GameName, string SavePath, string ExePath)
{
if (!File.Exists(docname))
{
CreateXml();
}
XDocument doc = XDocument.Load(docname);
XElement Game = doc.Element("Game");
Game.Add(new XElement("GameName", GameName), new XElement("SavePath", SavePath), new XElement("ExePath", ExePath));
doc.Save(docname);
}
private static void CreateXml()
{
XDocument SaveGameManager = new XDocument();
SaveGameManager.Declaration = new XDeclaration("1.0", "utf-8", "yes");
XElement Game = new XElement("Game");
SaveGameManager.Add(Game);
SaveGameManager.Save(docname);
}
现在我需要能够使用这些值,更具体地说,我需要在下拉菜单中使用GameName字符串。考虑到我还不是很有经验,我最简单的选择是什么:)
编辑:这是我的xmlfile
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Game>
<GameName>sfsdf</GameName>
<SavePath>6835-256x256x8 (1).png</SavePath>
<ExePath>arduino-1.8.2-windows.exe</ExePath>
<GameName>fasdf</GameName>
<SavePath>ClassDiagram simple.vsdx</SavePath>
<ExePath>GameOfLife.exe</ExePath>
</Game>