Fra*_*tel -4 c# xml class-structure winforms
我正在尝试将我的XML类与Math类分开.我正在读一个xml文件,查找该人开始的时间并将其放入字符串[](我想??)
public static string elementStartWeek()
{
XmlDocument xmldoc = new XmlDocument();
fileExistsWeek(xmldoc);
XmlNodeList nodeStart = xmldoc.GetElementsByTagName("Start");
int count2 = 0;
string[] starttxtWeek = new string[count2];
for (int i = 0; i <= nodeStart.Count; i++)
{
starttxtWeek[count2] = nodeStart[i].InnerText;
count2++;
}
return starttxtWeek[count2];
}
Run Code Online (Sandbox Code Playgroud)
我想将数组带入我的Math类并将时间转换为十进制值进行计算.我的Math类似乎将其识别为字符串而不是数组.
public static void startHour()
{
string weekStart = WidgetLogic.elementStartWeek();
string startTime = "";
if (1 == 1)
{
startTime = weekStart;
MessageBox.Show(weekStart);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望weekStart在Math.cs中抛出一个错误.为什么这不会引发错误?
我正在调用startHour()UI对话框DetailerReport
public DetailerReports()
{
InitializeComponent();
Math.startHour();
}
Run Code Online (Sandbox Code Playgroud)
EDIT1这是XML结构
<?xml version="1.0" encoding="utf-8"?>
<Form1>
<Name Key="11/19/2014 11:26:13 AM">
<Date>11/19/2014</Date>
<JobNum></JobNum>
<RevNum></RevNum>
<Task></Task>
<Start>11:26 AM</Start>
<End>11:26 AM</End>
<TotalTime>55870781</TotalTime>
</Name>
.....
Run Code Online (Sandbox Code Playgroud)
您的方法只返回一个string不是数组.这是第一个问题,第二个问题是你用0初始化数组.
public static string[] elementStartWeek()
{
XmlDocument xmldoc = new XmlDocument();
fileExistsWeek(xmldoc);
XmlNodeList nodeStart = xmldoc.GetElementsByTagName("Start");
int count2 = 0;
string[] starttxtWeek = new string[nodeStart.Count];
for (int i = 0; i < nodeStart.Count; i++)
{
starttxtWeek[i] = nodeStart[i].InnerText;
count2++;
}
return starttxtWeek;
}
Run Code Online (Sandbox Code Playgroud)