【发布时间】:2018-07-23 14:02:30
【问题描述】:
大家好,我是 C# 新手。
我尝试从名为“GetAllKschl”的方法返回结果“totalAmount”。在这种方法中,我返回了一个包含“KSCHL、KSCHLData、价格、件数和总价格”的列表。
所以在我的新方法中,我需要所有“totalPrice”的总金额。
第一种方法:
public List<Result> GetAllKschl(string fileNameResult, string fileNameData)
{
List<Result> listResult = new List<Result>();
docResult.Load(fileNameResult);
docData.Load(fileNameData);
var resultList = docResult.SelectNodes("//root/CalculationLogCompact/CalculationLogRowCompact");
foreach (XmlNode nextText in resultList)
{
XmlNode KSCHL = nextText.SelectSingleNode("KSCHL");
string nextKschl = KSCHL.InnerText;
// ... and so on...
if (pieces > 0 && totalPrice > 0)
{
listResult.Add(new Result(nextKschl, nextKSCHLData, nextEinzelpreis, pieces, totalPrice));
}
}
return listResult;
}
第二种方法:(不知道具体怎么做)
public decimal GetTotalAmount(string amount, string totalAmount)
{
string total = GetAllKschl(amount, totalAmount); // ??
return total;
}
所以在这里我只想拥有 TotalAmount(来自 GetAllKschl 的每个 totalPrice)而不是来自 GetAllKschl 的整个列表。我该怎么做?
这是我的课堂结果:
public class Result
{
public string KSCHL { get; set; }
public string Info { get; set; }
public int individualPrice { get; set; }
public int Pieces { get; set; }
public int TotalCosts { get; set; }
public Result(string kschl, string info, int individualPrice, int pieces, int totalCosts)
{
KSCHL = kschl;
Info = info;
IndividualPrice = individualPrice;
Pieces = pieces;
TotalCosts = totalCosts;
}
}
【问题讨论】:
-
你能告诉我的课程
Result吗? -
string total = GetAllKschl(amount, totalAmount).Count,即如果结果实际上是一个列表而不是某种模态。
-
GetAllKschl的参数是字符串,但它们似乎指向文件名。 -
@Tatranskymedved 我用它编辑了我的问题。
-
无关:我建议使用英文变量名。尤其是在这种情况下,您在国际论坛上寻求支持会派上用场。第二:我建议重新考虑选择 int 作为数量,尽管它比 double 好。见stackoverflow.com/a/693376/982149 和stackoverflow.com/a/3730040/982149
标签: c#