这是我的代码
Module Module1
Private Delegate Sub word(ByVal A As String, ByVal B As String, C As String)
Dim A, B, C As String
Sub Main()
Console.WriteLine("type something")
A = Console.ReadLine()
Console.WriteLine("type something else")
B = Console.ReadLine()
Console.WriteLine("type something else")
C = Console.ReadLine()
Dim objword As New word(AddressOf first)
objword(A, B, C)
first(A, B, C)
objword = New word(AddressOf Second)
objword(A, B, C)
Second(A, B, C)
objword = New word(AddressOf third)
objword(A, B, C)
third(A, B, C)
End Sub
Sub first(ByVal A As String, ByVal B As String, C As String)
Console.WriteLine(A)
End Sub
Sub Second(ByVal A As String, ByVal B As String, C As String)
Console.WriteLine(B)
End Sub
Sub third(ByVal A As String, ByVal B As String, C As String)
Console.WriteLine(C)
Console.ReadKey()
End Sub
End Module
当我运行它时,它会打印 A 和 B 字符串两次,但 C 字符串只打印一次。但是,如果我按回车键,它确实会第二次打印 C 刺痛。我知道 console.readkey 正在这样做。
我的问题是:
为什么字符串打印两次?
为什么 console.readkey 会阻止打印最后一个刺痛?
如何使字符串只打印一次?
编辑:通过将 console.readkey 移动到 sub main 的末尾,所有字符串打印两次