> type XList<'T> (_collection : seq<'T>) =
inherit List<'T> (_collection)
member this.Add _item = if not <| this.Contains _item then base.Add _item
new () = XList<'T> (Seq.empty<'T>);;
inherit List<'T> (_collection)
--------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
stdin(47,9): error FS0945: Cannot inherit a sealed type
我的理解是 List<'T> 实际上没有密封。不?
此外,这似乎在 F# 交互之外工作得很好。确切的代码在我的 F# 项目中,编译器会毫无怨言地处理它。我在几个 C# 项目中也发生了同样的事情。代码在每种情况下都按预期工作。
通常,我只是使用静态方法扩展 List<'T> (以“F# 方式”进行),但隐藏 List.Add 也应该可以正常工作。