本文整理汇总了VB.NET中System.Console.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.WriteLine方法的具体用法?VB.NET Console.WriteLine怎么用?VB.NET Console.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Console 的用法示例。
在下文中一共展示了Console.WriteLine方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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.WriteLine 输出:
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: TipCalculator
Public Module TipCalculator
Private Const tipRate As Double = 0.18
Public Sub Main(args As String())
Dim billTotal As Double
If (args.Length = 0) OrElse (Not Double.TryParse(args(0), billTotal)) Then
Console.WriteLine("usage: TIPCALC total")
Return
End If
Dim tip As Double = billTotal * tipRate
Console.WriteLine()
Console.WriteLine($"Bill total:{vbTab}{billTotal,8:c}")
Console.WriteLine($"Tip total/rate:{vbTab}{tip,8:c} ({tipRate:p1})")
Console.WriteLine("".PadRight(24, "-"c))
Console.WriteLine($"Grand total:{vbTab}{billTotal + tip,8:c}")
End Sub
End Module
'Example Output:
'---------------
' >tipcalc 52.23
'
' Bill total: $52.23
' Tip total/rate: $9.40 (18.0 %)
' ------------------------
' Grand total: $61.63
开发者ID:VB.NET开发者,项目名称:System,代码行数:28,代码来源:Console.WriteLine
示例3: Example
Module Example
Public Sub Main()
Dim lines() As String = { "This is the first line.", _
"This is the second line." }
' Output the lines using the default newline sequence.
Console.WriteLine("With the default new line characters:")
Console.WriteLine()
For Each line As String In lines
Console.WriteLine(line)
Next
Console.WriteLine()
' Redefine the newline characters to double space.
Console.Out.NewLine = vbCrLf + vbCrLf
' Output the lines using the new newline sequence.
Console.WriteLine("With redefined new line characters:")
Console.WriteLine()
For Each line As String In lines
Console.WriteLine(line)
Next
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:22,代码来源:Console.WriteLine 输出:
With the default new line characters:
This is the first line.
This is the second line.
With redefined new line characters:
This is the first line.
This is the second line.
示例4: Example
Module Example
Public Sub Main()
Dim rnd As New Random()
' Generate five random Boolean values.
For ctr As Integer = 1 To 5
Dim bool As Boolean = Convert.ToBoolean(rnd.Next(0, 2))
Console.WriteLine("True or False: {0}", bool)
Next
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:10,代码来源:Console.WriteLine 输出:
True or False: False
True or False: True
True or False: False
True or False: False
True or False: True
示例5: Example
Module Example
Public Sub Main()
Console.WriteLine("Today's date: {0:D}", DateTime.Now)
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:5,代码来源:Console.WriteLine 输出:
Today's date: Friday, April 1, 2016
示例6: Example
Module Example
Public Sub Main()
' Assign 10 random integers to an array.
Dim rnd As New Random()
Dim numbers(9) As Integer
For ctr As Integer = 0 To numbers.GetUpperBound(0)
numbers(ctr) = rnd.Next
Next
' Determine whether the numbers are even or odd.
For Each number In numbers
Dim even As Boolean = (number mod 2 = 0)
Console.WriteLine("Is {0} even:", number)
Console.WriteLine(even)
Console.WriteLine()
Next
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:Console.WriteLine
示例7: Example
Module Example
Public Sub Main()
Dim values() As Object = { True, 12.632, 17908, "stringValue",
"a"c, 16907.32d }
For Each value In values
Console.WriteLine(value)
Next
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:9,代码来源:Console.WriteLine 输出:
True
12.632
17908
stringValue
a
16907.32
示例8: MainClass
' 导入命名空间
Imports System
public class MainClass
Shared Sub Main()
Dim twelve As Integer = 12
Dim five As Integer = 5
Console.WriteLine("{0} + {1} = {2}", _
twelve, five, twelve + five)
Console.WriteLine("{0} - {1} = {2}", _
twelve, five, twelve - five)
Console.WriteLine("{0} * {1} = {2}", _
twelve, five, twelve * five)
End Sub
End Class
开发者ID:VB程序员,项目名称:System,代码行数:18,代码来源:Console.WriteLine
注:本文中的System.Console.WriteLine方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论