本文整理汇总了VB.NET中System.Console.Out属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.Out属性的具体用法?VB.NET Console.Out怎么用?VB.NET Console.Out使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Console
的用法示例。
在下文中一共展示了Console.Out属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.IO
Module Example
Public Sub Main()
' Get all files in the current directory.
Dim files() As String = Directory.GetFiles(".")
Array.Sort(files)
' Display the files to the current output source to the console.
Console.WriteLine("First display of filenames to the console:")
Array.ForEach(files, Function(s) WriteOutput(s))
Console.Out.WriteLine()
' Redirect output to a file named Files.txt and write file list.
Dim sw As StreamWriter = New StreamWriter(".\Files.txt")
sw.AutoFlush = True
Console.SetOut(sw)
Console.Out.WriteLine("Display filenames to a file:")
Array.ForEach(files, Function(s) WriteOutput(s))
Console.Out.WriteLine()
' Close previous output stream and redirect output to standard output.
Console.Out.Close()
sw = New StreamWriter(Console.OpenStandardOutput())
sw.AutoFlush = True
Console.SetOut(sw)
' Display the files to the current output source to the console.
Console.Out.WriteLine("Second display of filenames to the console:")
Array.ForEach(files, Function(s) WriteOutput(s))
End Sub
Private Function WriteOutput(s As String) As Boolean
Console.Out.WriteLine(s)
Return True
End Function
End Module