我的函数的返回值有一些问题。我想做的是从中获取一个元素值XML_File
并返回该值,以便我可以在Form_Load
.
我尝试处理该XML_Array_Load
功能,但出现以下错误。(Form_Load
由于其他函数的错误,尚未测试。)
XML_Array_Load 函数错误:
错误 1 由于 'Program.Form1.XML_Array_Load(System.Collections.Generic.Dictionary, System.Collections.Generic.Dictionary)' 返回 void,return 关键字后面不能跟对象表达式
C#代码:
static void XML_Array_Load(Dictionary<string, string> Data_Array, Dictionary<string, string> Elements_Array)
{
// XML File
String xmlfile = Data_Array["XML_File"];
// XML Page Check
if (File.Exists(xmlfile))
{
XmlDocument doc = new XmlDocument();
// If Page Exist Load XML File
doc.Load(xmlfile);
foreach (KeyValuePair<string, string> Element in Elements_Array)
{
// Get Element From Dictionary Array
String Element_Name = Element.Key;
String Element_Type = Element.Value;
// Get Element_Name from XMLFile
String Value = String.Format("XMLFILE/{0}", Element_Name);
// Get Element_Name Value From XMLFile
XmlNode Element_Value = doc.SelectSingleNode(Value);
// Check If Element_Value Is Null Or Not
if (Element_Value != null)
{
return Element_Value;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Start Data Array
Dictionary<string, string> Data_Array = new Dictionary<string, string>();
// XML_File path is come here
Data_Array.Add("XML_File", "../Debug/XMLFiles/Settings.xml");
// This is the element what i need to get the value from XML_File
Elements_Array.Add("Active", "");
// Send Arrays To Function and get function result
String Return_Value = XML_Array_Insert(Data_Array, Elements_Array);
// Here will setup textBox4.Text with the value
textBox4.Text = Return_Value.InnerText;
}