私有静态和公共静态之间的区别。 [英] difference between private static and public static.

查看:104
本文介绍了私有静态和公共静态之间的区别。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

任何人都可以告诉我公共静态和私有静态之间的区别

方法。


它们是怎样的分配和访问?


提前感谢。

Hi all,
can anyone tell me differene between public static and private static
method.

how they are allocated and access?.

thanks in advance.

推荐答案

它是'只是一个无障碍的问题。公共静态成员将可用于任何具有对声明

静态成员的程序集的引用的程序集。私有静态成员只能访问

来自班级。您可以通过类型访问它们,而不是生成它们声明类型的
实例。它们在堆栈上分配

或堆,具体取决于它们是否为值类型或引用类型(

所有类型)。

" archana" < tr ************** @ yahoo.com写信息

新闻:11 **************** ******@k21g2000cwa.googlegr oups.com ...
It''s simply a matter of accessibility. Public static members will be
available to any assembly that has a reference to the assembly where the
static member is declared.. Private static members will only be accessible
from within the class. You access them via the type, rather than making
instances of the type they are declared in. They are allocated on the stack
or heap, depending on whether they are value types or reference types (as
all types are).
"archana" <tr**************@yahoo.comwrote in message
news:11**********************@k21g2000cwa.googlegr oups.com...

大家好,

任何人都可以告诉我公众之间的差异静态和私有静态

方法。


如何分配和访问?


提前感谢。
Hi all,
can anyone tell me differene between public static and private static
method.

how they are allocated and access?.

thanks in advance.



我认为主要区别在于私有静态方法只能通过其他方法访问
班级。
I believe that the main difference is that the private static methods are
only accessible by other methods in the class.


Scott M.< s - *** @ nospam.nospamwrote:
Scott M. <s-***@nospam.nospamwrote:

It只是一个无障碍问题。公共静态成员将可用于任何引用

静态成员的程序集的程序集。
It''s simply a matter of accessibility. Public static members will be
available to any assembly that has a reference to the assembly where the
static member is declared..



是。

Yes.


私人静态会员只能在班级内访问


Private static members will only be accessible
from within the class.



和该类中的嵌套类。

And nested classes within that class.


您可以通过类型访问它们,而不是使

声明它们的类型的实例。它们在堆栈上分配

或堆,具体取决于它们是值类型还是引用类型(如

所有类型都是)。
You access them via the type, rather than making
instances of the type they are declared in. They are allocated on the stack
or heap, depending on whether they are value types or reference types (as
all types are).



否 - 静态变量*总是*在堆栈上分配,无论是
它们是值类型还是引用类型。 (另一个例子是过度简化失败的地方

。)


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复小组,请不要给我发邮件

No - static variables are *always* allocated on the stack, whether
they''re value types or reference types. (Just another example of where
the oversimplification fails.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于私有静态和公共静态之间的区别。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆