Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 216
Lyndon White Avatar asked May 18 '11 02:05

Lyndon White


People also ask

What is the difference between internal and public?

Internal is only available within the assembly it resides in. Public is available to any assembly referencing the one it resides in. If you can access the internal class from another assembly you either have "InternalsVisibleTo" set up, or you're not referencing the class you think you are.

What is difference between internal and private in C #?

protected internal: The type or member can be accessed by any code in the assembly in which it's declared, or from within a derived class in another assembly. private protected: The type or member can be accessed by types derived from the class that are declared within its containing assembly.

What is the meaning of internal access?

Internal access refers to giving full transparency to any necessary pre-release access within government, as deemed appropriate by the government.

What is an internal class in C#?

The internal keyword is an access modifier for types and type members. We can declare a class as internal or its member as internal. Internal members are accessible only within files in the same assembly (. dll). In other words, access is limited exclusively to classes defined within the current project assembly.


2 Answers

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
like image 82
Tomas Petricek Avatar answered Sep 17 '22 02:09

Tomas Petricek


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.

like image 39
Charles Lambert Avatar answered Sep 18 '22 02:09

Charles Lambert