,所以我显示从开始的每一个名称的第一个字母,一路到Z如何让这个更好的代码和更优化的
一些事情是这样的:
一个
安东尼
艾伦
...
乙
鲍勃
生成器
....
Ç
Charyl
卡尔
...
ž
Zoah
....
我怎样才能使这个代码更优化,使用更少线?
int _a = 0;
int _b = 0;
int _c = 0;
...
...
..
int _z = 0;
protected void ListItem(List<Customer>.Enumerator cust)
{
if (cust.MoveNext())
{
Customer t = cust.Current;
string[] list = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "v", "z" };
var output = list.Aggregate("", (current, listitem) => current + (Environment.NewLine + "<h1 id='" + listitem.ToUpper() + "'><span>" + listitem.ToUpper() + "</span></h1>"));
string _name = t.Name.Substring(0, 1).ToUpper();
if (_name == list[0].ToUpper())
{
if (_a == 0)
{
l = new Literal();
l.Text = "<h1 id='A'><span>A</span></h1>" + Environment.NewLine;
.....
_a = 1;
}
if (_name == list[1].ToUpper())
{
if (_b == 0)
{
l = new Literal();
l.Text = "<h1 id='B'><span>A</span></h1>" + Environment.NewLine;
.....
_b = 1;
}
}
...
....
....
...
doing through Z
}
@Abu欢迎您。 – Aristos 2011-06-04 02:02:54