更新:2010 年 8 月
按从右到左的顺序将函数应用于从两个集合中提取的元素对,并在整个计算过程中使用一个累加器参数。 两个输入数组的长度必须相同,否则将引发 ArgumentException。
命名空间/模块路径: Microsoft.FSharp.Collections.Array
程序集:FSharp.Core(在 FSharp.Core.dll 中)
// Signature:
Array.foldBack2 : ('T1 -> 'T2 -> 'State -> 'State) -> 'T1 [] -> 'T2 [] -> 'State -> 'State
// Usage:
Array.foldBack2 folder array1 array2 state
参数
- folder 
 类型:'T1 -> 'T2 -> 'State -> 'State- 要更新为输入元素指定的状态的函数。 
- array1 
 类型:'T1 []- 第一个输入数组。 
- array2 
 类型:'T2 []- 第二个输入数组。 
- state 
 类型:'State- 初始状态。 
异常
| 异常 | Condition | 
|---|---|
| 在输入数组的长度不同时引发。 | 
返回值
最终状态。
备注
此函数在 .NET 程序集中名为 FoldBack2。 如果从 F# 以外的 .NET 语言中访问成员,或通过反射访问成员,请使用此名称。
示例
下面的代码演示如何使用 Array.foldBack2。
type Transaction =
    | Deposit
    | Withdrawal
let transactionTypes = [| Deposit; Deposit; Withdrawal |]
let transactionAmounts = [| 100.00; 1000.00; 95.00 |]
let initialBalance = 200.00
let endingBalance = Array.foldBack2 (fun elem1 elem2 acc ->
                        match elem1 with
                        | Deposit -> acc + elem2
                        | Withdrawal -> acc - elem2)
                        transactionTypes
                        transactionAmounts
                        initialBalance
printfn "Ending balance: $%.2f" endingBalance
Output
平台
Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2
版本信息
F# 运行时
受以下版本支持:2.0、4.0
Silverlight
受以下版本支持:3
请参见
参考
Microsoft.FSharp.Collections 命名空间 (F#)
修订记录
| Date | 修订记录 | 原因 | 
|---|---|---|
| 2010 年 8 月 | 添加了代码示例。 | 信息补充。 |