作者:VB.NET开发
项目:Syste
' 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
作者:VB.NET开发
项目:Syste
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
作者:VB.NET开发
项目:Syste
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
作者:VB.NET开发
项目:Syste
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
作者:VB.NET开发
项目:Syste
Module Example
Public Sub Main()
Console.WriteLine("Today's date: {0:D}", DateTime.Now)
End Sub
End Module
作者:VB.NET开发
项目:Syste
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
作者:VB.NET开发
项目:Syste
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
作者:VB程序
项目:Syste
' 导入命名空间
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