Search code examples
oopf#privateinternal

what is the difference between internal and private


In F# what is the difference between an internal method and a private method.

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


Solution

  • 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