开发者

Is it possible to declare mutable and immutable values/bindings simultaneously?

For example I want to declare

let len, (*mutable*) i =
            if s.Length >= 2 && s.[0] = '0' && (s.[1] = 'x' || s.[1] = 'X') then
                (s.Length - 2, 2)
            else (s.Length, 0)

constant binding len and mutable i, is it possible ?

Added : I will use references开发者_开发技巧 then

    let len, i =
        if s.Length >= 2 && s.[0] = '0' && (s.[1] = 'x' || s.[1] = 'X') then
            (s.Length - 2, ref 2)
        else (s.Length, ref 0)


No. mutable applies to the entire let binding. You'll have to do:

let len, i = ...
let mutable i = i
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜