好的,这让我很生气.这段代码怎么可能不起作用?
open System.Collections.Generic
type testing (a:int)=
let test = [Empty]
member p.GetHashCode =
fun () -> printfn "called hash";0
override p.Equals(other:obj) =
printfn "called equals"
true
interface IEquatable<testing> with
override p.Equals(other:testing) =
true
static member op_Equality (other:obj) = printfn "called op" ;true
let dict2 = new Dictionary<testing,int>()
dict2.[(testing 50)] <- 50
dict2.[(testing 50)]
Run Code Online (Sandbox Code Playgroud)
当试图从字典中取出并且不调用任何提供的方法时,代码段就会死掉.我今天只是疯了还是这里有什么问题?
你还没有使用过override
修饰符p.GetHashCode
(不像p.Equals
).我的F#-fu缺乏,但这对我来说听起来不错.它打印出"被叫散列"吗?如果没有,那就是原因,我强烈怀疑......
归档时间: |
|
查看次数: |
152 次 |
最近记录: |