我想現在是Object.ToString()
但我不確定...謝謝!什麼取代了棄用的any_to_string函數?
1
A
回答
8
我想獲得any_to_string功能的唯一方法是使用 「%A」 格式。警告告訴你這一點。
let any_to_string = sprintf "%A"
這並不調用的ToString()。對於像列表這樣的簡單類型,.ToString()已經產生了很好的表示。但是,當使用自己的自定義類型時,%A格式化程序更有用。例如,在樹結構的情況下,它沿着樹行走。
如果你想在對象上調用的ToString(),您可以用「%O」格式化。
例子:
type Tree = Node of Tree * Tree | Leaf
let myTree = Node(Node(Leaf,Leaf),Node(Leaf,Node(Leaf,Leaf)))
和FSI:
> myTree.ToString();;
val it : string = "FSI_0002+Tree+Node"
> sprintf "%O" myTree;;
val it : string = "FSI_0002+Tree+Node"
> sprintf "%A" myTree;;
val it : string = "Node (Node (Leaf,Leaf),Node (Leaf,Node (Leaf,Leaf)))"
3
你可以用sprintf:
let a = [1;2;3]
let b = sprintf "%A" a
1
怎麼樣string
功能?
> string [1..3];;
val it : string = "[1; 2; 3]"
相關問題
- 1. 什麼取代了iOS 5棄用的加速度計:didAccelerate?
- 2. 在OS X Lion中棄用了CDSA。什麼取代它?
- 3. 對於MPAndroidChart已棄用的setDrawCubic()的替代函數是什麼?
- 4. iTextSharp OcspClientBouncyCastle構造函數已棄用,替代項是什麼?
- 5. 什麼取代了函數式編程中的MVC模式?
- 6. 在Angular2單元測試中什麼取代了棄用的提供?
- 7. 什麼取代了BulletSharp.ContactAdded?
- 8. 什麼取代了usbioctl.h?
- 9. 什麼取代了WearableListView.Adapter?
- 10. XMLHttpRequest已棄用。代替使用什麼?
- 11. 爲什麼我放棄了iframe的src?
- 12. 爲什麼在node.js v4.0.0中已經棄用了很多util.is *函數?
- 13. PHP中的函數已棄用,現在應該使用什麼?
- 14. 是否已棄用/取代FriendPickerFragment?應該使用什麼?
- 15. kube-up.sh已棄用。什麼是替代
- 16. 什麼取代了Smarty的3
- 17. 爲什麼std :: forward放棄了constexpr- ness?
- 18. JavaScript函數方法調用了什麼?
- 19. 函數調用時發生了什麼?
- 20. 這段代碼調用了什麼函數?
- 21. 什麼已經取代UITableViewCell setText setText已被棄用?
- 22. 棄用函數的用法
- 23. MapDB棄用函數
- 24. Symfony棄用函數
- 25. 這個函數在Facebook的JavaScript源代碼中做了什麼?
- 26. 什麼時候禁用了棄用的Twitter API版本1?
- 27. 棄用:函數eregi()已棄用
- 28. R函數`poly`真的做了什麼?
- 29. Web服務取代了什麼?
- 30. 是什麼取代了Indy TIdHTTP.DoRequest?
是它唯一的其他可能的替代? – Stringer 2010-05-15 05:45:32
我這麼認爲。 (更多的字符達到評論最低) – Brian 2010-05-15 09:12:01