c#中的访问修饰符 [英] access modifiers in c#

查看:104
本文介绍了c#中的访问修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#.net中的访问修饰符是什么?



what is access modifiers in c# .net?

public :
private :
protected :
internal :
protected internal :





哪里可以使用这个?

它们有什么区别?

给我就是这样的例子。



i更新,所以用简单的语言给出答案。



Gaurang Raval。

Fresher(实习生)



where I can use this all?
what is difference between them?
Give me live example for that.

i am fresher so give answer in easy language.

Gaurang Raval.
Fresher (trainee)

推荐答案

访问修饰符是面向对象编程的一个不可或缺的部分。



他们支持封装的概念,这促进了隐藏功能的想法



访问修饰符允许您定义对某些功能有无权访问



  • 公共

    - 没有限制访问

    - 类型或成员可以由同一程序集中的任何其他代码或引用它的另一个程序集访问。
  • protected

    -Access仅限于在类定义和从类继承的任何类中。

    - 类型或成员只能由同一个类或结构中的代码访问,或者在从该类派生的类中访问。
  • 内部

    -Access仅限于当前项目程序集中定义的类。

    -类型或成员只能通过相同类或结构中的代码访问。
  • private

    -Access仅限于类定义中;如果没有正式指定,则这是默认的访问修饰符类型。

    - 类型或成员可以被同一程序集中的任何代码访问,但不能访问其他程序集。
Access modifiers are an integral part of object-oriented programming.

They support the concept of encapsulation, which promotes the idea of hiding functionality.

Access modifiers allow you to define who does or doesn't have access to certain features.

  • public
    -No restrictions to access
    -The type or member can be accessed by any other code in the same assembly or another assembly that references it.
  • protected
    -Access is limited to within the class definition and any class that inherits from the class.
    -The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
  • internal
    -Access is limited exclusively to classes defined within the current project assembly.
    -The type or member can be accessed only by code in the same class or struct.
  • private
    -Access is limited to within the class definition; This is the default access modifier type if none is formally specified.
    -The type or member can be accessed by any code in the same assembly, but not from another assembly.


我认为最好的选择是拿一本好书然后阅读有关修饰符的内容。

这些将在初始章节中详细介绍。
I think the best bet for you is to pick up a good book and then read about modifiers.
These would be described in detail in the initial chapters.


公共成员:公共成员可以在项目的任何位置以及其他项目中访问。



私人会员:私人会员可以在班级内的任何地方访问,而不是在班级以外。



内部成员:内部成员可以在项目的任何地方访问。



受保护的成员:受保护的成员可以在成员申报的类别以及来自的类别中访问。



protected internal:受保护的内部成员享受双重效果。可以在prject中的任何地方访问,以及如果该类继承另一个类,那么在其他类中项目然后它也可以被其他项目访问。
public member:public member can be accessible any where in the project as well as other project also.

private member :private member can be accessible anywhere within a class itself not outside from that class.

Internal member: Internal member can b accessible anywhere whithin a project.

protected member :protected member can be accessible within a class where member declare as well as derrived class also.

protected internal : protected internal member enjoy dual effect.it is accessible anywhere in the prject as well as if that class is inherite one other class and that is in other project then only it can be accessible to other project also.


这篇关于c#中的访问修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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