开发者

Difference between these two syntaxes

type IFooable =
  abstract Foo : int -> int

type IFooable2 =
  abstract Foo : a : int -> int

type MyClass() =
    interface IFooable2 with
        member this.Foo(b) = 7

What is the differen开发者_开发问答ce between IFooable and IFooable2 ? Are they equivalent ? What is the purpose of it in the case of my example ? When to use it ?


IFooable2 names its parameter; IFooable does not.

This matters when systems reflect on parameter names. As an example, when you use WCF with an interface type marked up with ServiceContractAttribute, by default WCF uses the parameter names in the interface to control the names that appear in the XML projection of data on the wire.

This also matter for tooling, for example, reference this F# code from C#, declare a variable of each type, and look at the intellisense tooltips on each method.

I'd recommend always declaring the parameter name (prefer the second version).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜