本文整理匯總了VB.NET中System.Console.Read方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Console.Read方法的具體用法?VB.NET Console.Read怎麽用?VB.NET Console.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Console
的用法示例。
在下文中一共展示了Console.Read方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Sample
' This example demonstrates the Console.Read() method.
Class Sample
Public Shared Sub Main()
Dim m1 As String = _
vbCrLf & _
"Type a string of text then press Enter. " & _
"Type '+' anywhere in the text to quit:" & _
vbCrLf
Dim m2 As String = "Character '{0}' is hexadecimal 0x{1:x4}."
Dim m3 As String = "Character is hexadecimal 0x{0:x4}."
Dim ch As Char
Dim x As Integer
'
Console.WriteLine(m1)
Do
x = Console.Read()
Try
ch = Convert.ToChar(x)
If Char.IsWhiteSpace(ch) Then
Console.WriteLine(m3, x)
If ch = vbLf Then
Console.WriteLine(m1)
End If
Else
Console.WriteLine(m2, ch, x)
End If
Catch e As OverflowException
Console.WriteLine("{0} Value read = {1}.", e.Message, x)
ch = Char.MinValue
Console.WriteLine(m1)
End Try
Loop While ch <> "+"c
End Sub
End Class
輸出:
Type a string of text then press Enter. Type '+' anywhere in the text to quit: The quick brown fox. Character 'T' is hexadecimal 0x0054. Character 'h' is hexadecimal 0x0068. Character 'e' is hexadecimal 0x0065. Character is hexadecimal 0x0020. Character 'q' is hexadecimal 0x0071. Character 'u' is hexadecimal 0x0075. Character 'i' is hexadecimal 0x0069. Character 'c' is hexadecimal 0x0063. Character 'k' is hexadecimal 0x006b. Character is hexadecimal 0x0020. Character 'b' is hexadecimal 0x0062. Character 'r' is hexadecimal 0x0072. Character 'o' is hexadecimal 0x006f. Character 'w' is hexadecimal 0x0077. Character 'n' is hexadecimal 0x006e. Character is hexadecimal 0x0020. Character 'f' is hexadecimal 0x0066. Character 'o' is hexadecimal 0x006f. Character 'x' is hexadecimal 0x0078. Character '.' is hexadecimal 0x002e. Character is hexadecimal 0x000d. Character is hexadecimal 0x000a. Type a string of text then press Enter. Type '+' anywhere in the text to quit: ^Z Value was either too large or too small for a character. Value read = -1. Type a string of text then press Enter. Type '+' anywhere in the text to quit: + Character '+' is hexadecimal 0x002b.