我的函数返回值有一些问题。我想要做的是从XML_File
获取元素值并返回该值,以便我可以在中使用它。C#winforms函数返回值
我试图处理XML_Array_Load
函数,我得到了下面的错误。 (该尚未因为在其他函数的错误的测试)
XML_Array_Load功能错误:
Error 1 Since 'Program.Form1.XML_Array_Load(System.Collections.Generic.Dictionary, System.Collections.Generic.Dictionary)' returns void, a return keyword must not be followed by an object expression
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;
}
你希望返回什么,一个'XmlNode'或'串'? –
不错的尝试。昨天,你已经赢得了大量的赞誉,用你的旧名字“matei zoc”提出了无构造/重复的问题。今天,你采取一个新的名字和开始相同的问题类型?极好。 – varg