I've got the following F# code:
//Array iter version
let toSecureString (s:string) =
let sString = new SecureString()
s |> Array.iter (fun cl -> sString.AppendChar cl)
sString
我试图将 .Net 字符串转换为 .Net SecureString。但当我尝试编译时,出现了类型不匹配的错误:
stdin(60,10): error FS0001: Type mismatch. Expecting a
string -> 'a
but given a
'b [] -> unit
The type 'string' does not match the type ''a []'
如果我没有指定s的类型,那么我看到的类型签名是这样的:
val toSecureString : char [] -> SecureString
但是我不想每次都手动创建一个char数组作为参数,这似乎缺少了什么。如何使得此代码能够接受传入的字符串参数?
如果有所不同,我正在测试 F# 2.0(Build 4.0.40219.1)。
欢迎任何提示。如果已经有人提出并解决了这个问题,请在评论中发布链接,我会关闭这个问题。
sString
之前没有释放它吗? - Lee