0
Public Function random_key(ByVal lenght As Integer) As String
    Randomize()
    Dim s As New System.Text.StringBuilder("")
    Dim b() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".ToCharArray()
    For i As Integer = 1 To lenght
        Randomize()
        Dim z As Integer = Int(((b.Length - 2) - 0 + 1) * Rnd()) + 1
        s.Append(b(z))
    Next
    Return s.ToString
    Console.WriteLine(s.ToString)

End Function

我想像 s=textbox1.text 或其他东西一样打印它...

4

1 回答 1

1

使用有什么问题Console.WriteLine

请注意,您不应将其放在方法中的return语句后面,因为 return 后面的代码是unreachable

Dim random As String = random_key(10)
Console.WriteLine(random)
于 2012-05-23T14:23:58.490 回答