【发布时间】:2016-09-26 00:09:45
【问题描述】:
我有这个ToString 用于写出对象的方法。我正在尝试将 for 循环转换为 foreach 循环。
不使用 LINQ。
任何指针将不胜感激。
public override string ToString()
{
StringBuilder output = new StringBuilder();
output.AppendFormat("{0}", count);
for (var index = 0; index < total; index++)
{
output.AppendFormat("{0}{1}{2} ", array[index], array[index].GetInfo,
string.Join(" ", array[index].Content(index)),
);
}
return output.ToString();
}
【问题讨论】:
-
为什么要近距离投票,因为这太广泛了?
-
好的,为什么要投反对票?这世界怎么这么宽泛?
-
minimal reproducible example 在这里很有用。
标签: c# for-loop foreach tostring