ExtraTopLevelOperators.printfn<'T> 函式 (F#)
更新:2010 年 5 月
printfn函數會列印到 stdout使用指定的格式,並加入 新行。
命名空間/模組路徑: Microsoft.FSharp.Core.ExtraTopLevelOperators
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
printfn : TextWriterFormat<'T> -> 'T
// Usage:
printfn format
參數
- format
型別:TextWriterFormat<'T>
備註
這個函式是名為 PrintFormatLine中 已編譯的組件。 如果從一個語言,F # 以外,或透過反映存取函式使用這個名稱。
範例
下列程式碼範例示範如何使用 printfn以 各種格式規範。 在格式規範的詳細資訊,請參閱 的 Printf 模組。
let isDone = false
printfn "Printing Boolean values: %b %b" isDone (not isDone)
let s1,s2 = "test1", @"C:\test2"
printfn "Printing strings (note literal printing of string with special character): %s%s" s1 s2
let i1, i2 = -123, 1891
printfn "Printing an integer in decimal form, with and without a width: %d %10d" i1 i2
printfn "Printing an integer in lowercase hexadecimal: %x or 0x%x" i1 i2
printfn "Printing as an unsigned integer: %u %u" i1 i2
printfn "Printing an integer as uppercase hexadecimal: %X or 0x%X" i1 i2
printfn "Printing as an octal integer: %o %o" i1 i2
printfn "Printing in columns."
for i in 115 .. 59 .. 1000 do
printfn "%10d%10d%10d%10d%10d" (10100015-i) (i-100) (115+i) (99992/i) (i-8388229)
let x1, x2 = 3.141592654, 6.022E23
printfn "Printing floating point numbers %e %e" x1 x2
printfn "Printing floating point numbers %E %E" x1 x2
printfn "Printing floating point numbers %f %f" x1 x2
printfn "Printing floating point numbers %F %F" x1 x2
printfn "Printing floating point numbers %g %G" x1 x2
printfn "Using the width and precision modifiers: %10.5e %10.3e" x1 x2
printfn "Using the flags:\nZero Pad:|%010d| Plus:|%+10d |LeftJustify:|%-10d| SpacePad:|% d|" 1001 1001 1001 1001
printfn "zero pad | |+- both | |- and ' ' | |' ' and 0 | | normal "
for i in -115 .. 17 .. 100 do
printfn "|%010d| |%+-10d| |%- 10d| |% 010d| |%10d|" (80-i) (i+85) (100+i) (99992/i) (i-80)
let d = 0.124M
printfn "Decimal: %M" d
printfn "Print as object: %O %O %O %O" 12 1.1 "test" (fun x -> x + 1)
printfn "%A" [| 1; 2; 3 |]
printfn "Printing from a function (no args): %t" (fun writer -> writer.WriteLine("X"))
printfn "Printing from a function with arg: %a" (fun writer (value:int) -> writer.WriteLine("Printing {0}.", value)) 10
平台
Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2
版本資訊
F# 執行階段
支援版本:2.0、4.0
Silverlight
支援版本:3
請參閱
參考
Core.ExtraTopLevelOperators 模組 (F#)
Microsoft.FSharp.Core 命名空間 (F#)
變更記錄
日期 |
History |
原因 |
---|---|---|
2010 年 5 月 |
加入程式碼範例。 |
資訊加強。 |