简体   繁体   English

printfn“%A”“c”使用F#

[英]printfn “%A” “c” using F#

By running printfn "%A" "c" , I get "c" . 通过运行printfn "%A" "c" ,我得到"c"

By running printfn "%s" "c" , I get c . 通过运行printfn "%s" "c" ,我得到c

Why the difference? 为什么不同? The same goes for char . char

The %A specifier tries to hint at object types - the "c" is it trying to show it is a string. %A说明符试图暗示对象类型 - "c"是它试图显示它是一个字符串。 When you do %s the compiler knows you want to print a string so it doesn't print the quotes 当您执行%s ,编译器知道您要打印字符串,因此它不会打印引号

Because printfn "%A" uses reflection, it displays results the same as values automatically printed out by F# Interactive. 因为printfn "%A"使用反射,所以它显示的结果与F#Interactive自动打印的值相同。 On the other hand, %s is for strings only, and it shows contents of strings. 另一方面, %s仅用于字符串,它显示字符串的内容。

The generic case of "%s" is "%O" when ToString methods are used. 当使用ToString方法时, "%s"的一般情况是"%O" The %A specifier is slow, but helpful for structural types and types without overridden ToString methods. %A说明符很慢,但对于没有重写ToString方法的结构类型和类型很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM