内部和私人有什么区别

发布于 2024-11-07 17:50:02 字数 61 浏览 0 评论 0原文

在 F# 中,内部方法和私有方法有什么区别。

我有一种感觉,它们的实现是相同的,但含义不同。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷月断魂刀 2024-11-14 17:50:02

可以从同一 .NET 程序集中的任何类型(或函数)访问内部方法。
private 方法只能从声明它的类型中访问。

这是一个显示差异的简单片段:

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

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
(り薆情海 2024-11-14 17:50:02

内部与公共相同,只是它仅在其声明的程序集中可见。私有仅在声明类型内部可见。

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.

小镇女孩 2024-11-14 17:50:02

内部实例可以在同一程序集中访问,而私有实例只能在定义中访问班级。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文