0
을 사용할 때 사전에 입력 된 키를 찾을 수 없다. 이렇게하면 화를 낼 수 있습니다. 이 코드가 어떻게 작동하지 않을 수 있습니까?F #
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)]
스 니펫은 사전을 가져 오려고 할 때 죽고 제공된 방법 중 하나를 호출하지 않습니다. 오늘 미쳤나요? 아니면 뭔가 잘못 됐나요?
남자가 바로 sooo입니다. 나는 두 시간 동안 벽에 머리를 두드렸다. Can not belive 나는 그것을 보지 않았다 – LDomagala
또한 GetHashCode 멤버는 실제로 nullary 함수를 반환하는 속성으로 정의됩니다. 메소드 대신 (''p.GetHashCode()'로 정의하고 아래의''fun() - ''부분을 생략하면) 실제로 재정의하지 않고 기본 구현을 숨기고 있다는 경고를 받게됩니다. – kvb