在 C# 中获取要相加的元素
我有以下代码 -
private static void convert()
{
webservice.Sum[] test = new webservice.Sum[1];
webservice.feed CallWebService = new webservice.feed();
foreach(XElement el in turnip.Descendants("row"))
{
test[0].person = el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "person"
).SingleOrDefault().Attribute("value").Value;
test[0].time = System.Convert.ToInt32(el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "time"
).SingleOrDefault().Attribute("value").Value);
test[0].erase = System.Convert.ToInt32(el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "erase"
).SingleOrDefault().Attribute("value").Value);
test[0]. available = el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "available"
).SingleOrDefault().Attribute("value").Value;
test[0].external = el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "external"
).SingleOrDefault().Attribute("value").Value;
CallWebService.updateFeed(test, year);
}
}
我需要做的是让测试数组中的“人”和“时间”元素分别相加。例如,它们是从 csv 中读取的,因此如果 csv 的帐户的值为 、 10、20 和 30。我希望它将帐户显示为具有所需的值 60。然后与擦除相同。这些将是运行时在表单中显示的所需值,然后将从 Web 服务返回人员值,如果帐户返回 40 而不是 60,则将显示发生错误。
现在澄清一下,我正在从网络服务获得响应,但它并不总是返回所需的值。来自网络服务的结果在网络表单上返回,我想在表单上获得来自网络服务的结果(我有)以及结果应该是什么,以比较或确认结果是否正确。因此,在运行时,表单会告诉我 csv 中帐户的添加值是多少,然后是 Web 服务结果返回的值。
I have the following code -
private static void convert()
{
webservice.Sum[] test = new webservice.Sum[1];
webservice.feed CallWebService = new webservice.feed();
foreach(XElement el in turnip.Descendants("row"))
{
test[0].person = el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "person"
).SingleOrDefault().Attribute("value").Value;
test[0].time = System.Convert.ToInt32(el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "time"
).SingleOrDefault().Attribute("value").Value);
test[0].erase = System.Convert.ToInt32(el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "erase"
).SingleOrDefault().Attribute("value").Value);
test[0]. available = el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "available"
).SingleOrDefault().Attribute("value").Value;
test[0].external = el.Descendants("var").Where
(
x => (string)x.Attribute("name") == "external"
).SingleOrDefault().Attribute("value").Value;
CallWebService.updateFeed(test, year);
}
}
What I need to do is to get the 'person' and 'time' elements in the test array to add up seperately. For instance they are getting read in from a csv, so if the csv had account with the values of , 10, 20 and 30. I would want it to show account as having the desired value of 60. Then the same with erase. These would be the desired values to be presented in the form when run, then the person values would be returned from the web service, if it came back 40 for account and not 60, that would show an error occuring.
To make it clear right now I am getting a response from the web service, however it will not always be the desired value returned. The reulst from the webservice are returned on a web form, I want to have the results from the web service on the form (which I have) and what the results should definately be to compare or confirm the reults are correct. So on run time the form will tell me what the added up values of account are from the csv, then what the web service results have returned.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像我通过聊天得到你的问题一样,我尝试解决你的问题。
这是如果你想获得整个 CSV 的总和:
Alex
like i got your problem via Chat i try to solve your problem.
This is if you want to get the sum of the whole CSV:
Alex