文本显示 += 古奇.划分分割(0, (收支分类 == 0 ? "非绑古币 | " : "<a href='payInfo.aspx?type=0" + 古奇.二号书签 + "'>非绑古币</a> | ") + (收支分类 == 1 ? "绑定古币 | " : "<a href='payInfo.aspx?type=1" + 古奇.二号书签 + "'>绑定古币</a> | ") + (收支分类 == 2 ? "积分收支 | " : "<a href='payInfo.aspx?type=2" + 古奇.二号书签 + "'>积分收支</a> | ") + (收支分类 == 3 ? "金币收支" : "<a href='payInfo.aspx?type=3" + 古奇.二号书签 + "'>金币收支</a>") );上面的代码用asp.net有几种写法?
时间: 2024-04-14 10:28:37 浏览: 88
在ASP.NET中,你可以使用以下两种写法来实现上述代码的功能:
1. 使用三元运算符:
```
+= (收支分类 == 0 ?非绑古币 | " : "<a href='payInfo.aspx?type=0" + 古奇.二号书签 + "'>非绑古币</a> | ");
+= (收支分类 == 1 ? "绑定古币 | " : "<a href='payInfo.aspx?type=1" + 古奇.二号书签 + "'>绑定古币</a> | ");
+= (收支分类 == 2 ? "积分收支 | " : "<a href='payInfo.aspx?type=2" + 古奇.二号书签 + "'>积分收支</a> | ");
+= (收支分类 == 3 ? "金币收支" : "<a href='payInfo.aspx?type=3" + 古奇.二号书签 + "'>金币收支</a>");
```
2. 使用if语句:
```
if (收支分类 == 0)
{
+= "非绑古币 | ";
}
else
{
+= "<a href='payInfo.aspx?type=0" + 古奇.二号书签 + "'>非绑古币</a> | ";
}
if (收支分类 == 1)
{
+= "绑定古币 | ";
}
else
{
+= "<a href='payInfo.aspx?type=1" + 古奇.二号书签 + "'>绑定古币</a> | ";
}
if (收支分类 == 2)
{
+= "积分收支 | ";
}
else
{
+= "<a href='payInfo.aspx?type=2" + 古奇.二号书签 + "'>积分收支</a> | ";
}
if (收支分类 == 3)
{
+= "金币收支";
}
else
{
+= "<a href='payInfo.aspx?type=3" + 古奇.二号书签 + "'>金币收支</a>";
}
```
这两种写法都可以根据收支分类的值来拼接不同的字符串,并将结果添加到文本中。选择哪种写法取决于你的个人偏好和代码结构。
阅读全文