How do you return multiple values and assign them to mutable variables?

后端 未结 3 1377
谎友^
谎友^ 2021-02-20 17:42

This is what I have so far.

let Swap (left : int , right : int ) = (right, left)

let mutable x = 5
let mutable y = 10

let (newX, newY) = Swap(x, y) //<--thi         


        
3条回答
  •  爱一瞬间的悲伤
    2021-02-20 18:18

    F# has "by reference" parameters just like C#, so you can write a classic swap function similarly:

    let swap (x: byref<'a>) (y: byref<'a>) =
        let temp = x
        x <- y
        y <- temp
    
    let mutable x,y = 1,2
    swap &x &y
    

提交回复
热议问题