我需要从VB中的0 - 9999
计算。如何制作格式0000 - 9999
,以便输出为:
0000, 0001, 0002, 0003, .......
我使用了以下代码
Dim p4num As Integer = 0
Dim p3num As Integer = 0
Dim p2num As Integer = 0
Dim p1num As Integer = 0
p4num += 1
If p4num = 10 Then
p4num = 0
p3num += 1
If p3num = 10 Then
p3num = 0
p2num += 1
If p2num = 10 Then
p2num = 0
p1num += 1
End If
End If
End If
但我会以另一种方式做到这一点。有什么想法吗?
答案 0 :(得分:3)
ToString()
可能会有所帮助。 <怎么样
myint.ToString("0000")
或
myint.ToString("D4");
答案 1 :(得分:3)
For i as integer = 0 to 9999
Debug.WriteLine(i.ToString("0000"))
next
未经测试的代码,但应该有用......
答案 2 :(得分:2)
您的指南
Dim numbers As IEnumerable(Of Integer) = Enumerable.Range(0, 9999).ToArray()
'object j = string.Join(", ", numbers);
For Each item As var In numbers
Console.WriteLine(item.ToString("#0000"))
Next