VB.Net Tutorial/Language Basics/Console Write

Материал из VB Эксперт
Версия от 15:54, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Concatenate strings in Console.WriteLine statement

<source lang="vbnet">Module Module1

   Sub Main()
       Dim WebSite As String
       Dim Publisher As String = "AAAA"
       Console.WriteLine("AAAA: " & Publisher)
       WebSite = "CCCC." & Publisher & ".DDDD"
       Console.WriteLine("String one " & WebSite)
   End Sub

End Module</source>

AAAA: AAAA
String one CCCC.AAAA.DDDD

Output string to the Console

<source lang="vbnet">Module Module1

    Sub Main( )
      Console.WriteLine("Hello from Module")
    End Sub
End Module</source>
Hello from Module

Reference variable index in Console.WriteLine

<source lang="vbnet">Module Module1

   Sub Main()
       Dim A As Double = 1.23456789
       Console.WriteLine("{0} {1} {2}", 1, 2, 3)
   End Sub

End Module</source>

1 2 3

Use Console.WriteLine to display various type variables

<source lang="vbnet">Module Module1

   Sub Main()
       Dim A As Integer = 100
       Dim B As Double = 0.123456789
       Dim Message As String = "Hello, VB World!"
       Console.WriteLine(A)
       Console.WriteLine("The value of A is " & A)
       Console.WriteLine(B)
       Console.WriteLine(B & " plus " & A & " = " & B + A)
       Console.WriteLine(Message)
   End Sub

End Module</source>

100
The value of A is 100
0.123456789
0.123456789 plus 100 = 100.123456789
Hello, VB World!

Variable index

<source lang="vbnet">Public Class Tester

   Public Shared Sub Main
       Console.WriteLine(String.Format( _
           "There are about {0} days in {1} years.", _
           365.25 * 3, 3, 17))

   End Sub

End Class</source>

There are about 1095.75 days in 3 years.

Write some text based on the specified data type

<source lang="vbnet">Module Module1

   Sub Main()
       Console.Write(True)
       Console.Write(25)
       Console.Write("Some text.")
       Console.WriteLine()
       Console.WriteLine()
       Console.WriteLine(True)
       Console.WriteLine(25)
       Console.WriteLine("Some text.")
   End Sub

End Module</source>

True25Some text.
True
25
Some text.