本文整理汇总了VB.NET中System.Console.Write方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.Write方法的具体用法?VB.NET Console.Write怎么用?VB.NET Console.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Console 的用法示例。
在下文中一共展示了Console.Write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Sample
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.
Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color
Private Shared thisDate As DateTime = DateTime.Now
Public Shared Sub Main()
Console.Clear()
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
"(U) Universal full date/time: {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:57,代码来源:Console.Write 输出:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
示例2: FormatConverter
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:25,代码来源:Console.Write
示例3: Person
Public Class Person
Public Property Name As String
Public Property BirthDate As DateTime
Public Property Height As Double
Public Property Weight As Double
Public Property Gender As Char
Public Property Remarks As String
Public Function GetDescription() As Object()
Return { Name, Gender, Height, Weight, BirthDate}
End Function
End Class
Module Example
Public Sub Main()
Dim p1 As New Person() With { .Name = "John", .Gender = "M"c,
.BirthDate = New DateTime(1992, 5, 10),
.Height = 73.5, .Weight = 207 }
p1.Remarks = "Client since 1/3/2012"
Console.Write("{0}: {1}, born {4:d} Height {2} inches, Weight {3} lbs ",
p1.GetDescription())
If String.IsNullOrEmpty(p1.Remarks) Then
Console.WriteLine()
Else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
If(Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth,
vbCrLf + " ", ""))
End If
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:30,代码来源:Console.Write 输出:
John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
示例4: Person
Public Class Person
Public Property Name As String
Public Property BirthDate As DateTime
Public Property Height As Double
Public Property Weight As Double
Public Property Gender As Char
Public Property Remarks As String
Public Function GetDescription() As Object()
Return { Name, Gender, Height, Weight, BirthDate}
End Function
End Class
Module Example
Public Sub Main()
Dim p1 As New Person() With { .Name = "John", .Gender = "M"c,
.BirthDate = New DateTime(1992, 5, 10),
.Height = 73.5, .Weight = 207 }
p1.Remarks = "Client since 1/3/2012"
Console.Write("{0}: {1}, born {2:d} Height {3} inches, Weight {4} lbs ",
p1.Name, p1.Gender, p1.BirthDate, p1.Height, p1.Weight)
If String.IsNullOrEmpty(p1.Remarks) Then
Console.WriteLine()
Else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
If(Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth,
vbCrLf + " ", ""))
End If
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:30,代码来源:Console.Write 输出:
John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
注:本文中的System.Console.Write方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论