有人能帮我把这段代码改回一个简单的for循环吗?
public class sT
{
public string[] Description { get; set; }
}
text = sT.Description.Aggregate(text, (current, description) =>
current + ("<option value=" + string.Format("{0:00}", j) + "'>" + j++ + ". " + description+ "</option>"));该代码遍历数组"Description“的元素,并创建一个选项列表。我想做一些不同的处理,但我不确定如何反向工程。任何建议都将非常受欢迎。
发布于 2011-11-03 18:25:06
Aggregate简单地循环遍历列表中的项,并将委托的结果传递给下一次对委托的调用。
第一个参数指定开始时的初始值。
foreach ( string description in sT.Description )
{
text += "<option value=" + string.Format("{0:00}", j) + "'>" + j++ + ". " + description+ "</option>";
}发布于 2011-11-03 18:26:23
foreach(var description in sT.Description)
{
text += String.Format("<option value={0:00}'>{1}.{2}</option>",
j,
j++,
description)
}发布于 2011-11-03 18:26:01
看起来像这样
foreach (string s in sT.Description)
text = text + ("<option value=" + string.Format("{0:00}", j) + "'>" + j++ + ". " + s + "</option>");https://stackoverflow.com/questions/7993208
复制相似问题