6

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.

Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137
  • 1
    I think it should be no different from C# http://stackoverflow.com/questions/3813485/internal-vs-private-access-modifiers – Sandeep G B May 18 '11 at 04:52

3 Answers3

14

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
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
3

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.

Charles Lambert
  • 5,042
  • 26
  • 47
0

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

Syed
  • 953
  • 1
  • 8
  • 11