在循环体中如何实现叠放效果
在图片管理系统中较为常见,图片需要每隔5个缩微图后换行,如下效果:
列1 列2
1 2
3 4
5 6
实现这个叠放效果特别简单:
VB.NET
C#
列1 列2
1 2
3 4
5 6
实现这个叠放效果特别简单:
VB.NET
Dim iLoop As Integer
Dim iSpan As Integer = 1
Response.Write("列1" + ControlChars.Tab)
Response.Write("列2<hr>")
For iLoop = 1 To 6
If iSpan Mod 2 = 0 Then
Response.Write(iLoop.ToString)
Response.Write("<hr>") '*表示遇2折行
Else
Response.Write(iLoop.ToString + ControlChars.Tab)
End If
iSpan += 1
Next
Dim iSpan As Integer = 1
Response.Write("列1" + ControlChars.Tab)
Response.Write("列2<hr>")
For iLoop = 1 To 6
If iSpan Mod 2 = 0 Then
Response.Write(iLoop.ToString)
Response.Write("<hr>") '*表示遇2折行
Else
Response.Write(iLoop.ToString + ControlChars.Tab)
End If
iSpan += 1
Next
C#
int iLoop;
int iSpan = 1;
Response.Write("列1" + ControlChars.Tab);
Response.Write("列2<hr>");
for (int iLoop = 1; iLoop <= 6; iLoop++) {
if (iSpan % 2 == 0) {
Response.Write(iLoop.ToString);
Response.Write("<hr>");
} else {
Response.Write(iLoop.ToString + ControlChars.Tab);
}
iSpan += 1;
}
int iSpan = 1;
Response.Write("列1" + ControlChars.Tab);
Response.Write("列2<hr>");
for (int iLoop = 1; iLoop <= 6; iLoop++) {
if (iSpan % 2 == 0) {
Response.Write(iLoop.ToString);
Response.Write("<hr>");
} else {
Response.Write(iLoop.ToString + ControlChars.Tab);
}
iSpan += 1;
}
已经有三个人问同样的问题了:)
具体的问题具体对待,但算法等同:)