开发者

what is the difference between internal and private

In F# what is the diff开发者_Go百科erence between an internal method and a private method.

I have a feeling that they are implemented the same, but mean something different.


An internal method can be accessed from any type (or function) in the same .NET assembly.
A private method can be accessed only from the type where it was declared.

Here is a simple snippet that shows the difference:

type A() = 
  member internal x.Foo = 1

type B() = 
  member private x.Foo = 1

let a = A()
let b = B()
a.Foo // Works fine (we're in the same project)
b.Foo // Error FS0491: 'Foo' is not defined


internal is the same as public, except that it is only visible inside the assembly it is delcared in. Private is only visible inside the declaring type.


internal instances can be accessed throughout the same assembly, while private instances can be accessed "ONLY" in the defining class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜