• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#ProgrammingLanguage学习笔记(四)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
第四章 基础概念
1.Protected internal (meaning protected or internal), which is selected by including both a protected and an internal modifier in the member declaration. The intuitive meaning of protected internal is "access limited to this program or types derived from the containing class."
Protected internal(意思是protected或者internal),在成员声明是同时选择protected和internal两个修饰符.protected internal的意思是"只有本程序内或者继承于该类的类型可以访问"
2.Namespaces implicitly have public declared accessibility. No access modifiers are allowed on namespace declarations.
Namespaces隐式地具有共有访问级别.在声明Namespaces的时候不允许用访问级别修饰符.
3.Types declared in compilation units or namespaces can have public or internal declared accessibility and default to internal declared accessibility.
在编译单元或者Namespaces声明的类型可以具有public或者internal访问级别,默认为internal访问级别.
4.Class members can have any of the five kinds of declared accessibility and default to private declared accessibility. (Note that a type declared as a member of a class can have any of the five kinds of declared accessibility, but a type declared as a member of a namespace can have only public or internal declared accessibility.)
类成员可以有五种访问级别,默认为private访问级别(注意,一个作为类成员定义的类型可以有任意五种访问级别中的一个,但是作为namespace成员定义的类型只能是public或者internal访问级别).
5.Struct members can have public, internal, or private declared accessibility and default to private declared accessibility because structs are implicitly sealed. Struct members introduced in a struct (that is, not inherited by that struct) cannot have protected or protected internal declared accessibility. (Note that a type declared as a member of a struct can have public, internal, or private declared accessibility, but a type declared as a member of a namespace can have only public or internal declared accessibility.)
结构成员可以具有public,internal,private访问级别,默认是private访问级别因为结构是隐式封闭的.结构中的结构类型成员(换句话说,不是那个结构的继承.译注:是组合不是继承)不能有protected或者protected internal访问级别.(注意作为结构的成员声明的类型可以具有public,internal或者private访问级别,但是作为命名空间成员申明的类型只能有public或者internal访问级别).
6.Interface members implicitly have public declared accessibility. No access modifiers are allowed on interface member declarations.
Enumeration members implicitly have public declared accessibility. No access modifiers are allowed on enumeration member declarations.
接口和枚举成员隐式地具有public访问级别.接口和枚举成员不能有访问修饰符.
7.Note that any ref and out parameter modifiers are part of a signature. Thus, F(int) and F(ref int) are unique signatures. Also, note that the return type and the params modifier are not part of a signature, so it is not possible to overload solely based on the return type or on the inclusion or exclusion of the params modifier. As such, the declarations of the methods F(int) and F(params string[]) identified in the previous example result in a compile-time error.
注意ref和out参数修饰符都是签名的部分.因此,F(int)和F(ref int)都是唯一的签名.另外,返回类型和params修饰符不是签名的部分,所以不能仅仅根据返回类型或者是否包含params修饰符来判定重载.于是,F(int)和F(params string[])在前面的例子中引发了编译时错误.
译注:上文中提到的引发编译时错误的语句如下:
interface ITest


8.A constant, field, property, event, or type introduced in a class or struct hides all base class members with the same name.
   A method introduced in a class or struct hides all nonmethod base class members with the same name and all base class methods with the same signature (method name and parameter count, modifiers, and types).
   An indexer introduced in a class or struct hides all base class indexers with the same signature (parameter count and types).
   The rules governing operator declarations  make it impossible for a derived class to declare an operator with the same signature as an operator in a base class. Thus, operators never hide one another.

   常量,字段,属性,事件或者类或结构中的类型 隐藏了基类中的同名成员.
   类或结构的方法隐藏了基类中的同名非方法成员和具有相同签名的方法成员(方法名和参数个数,形式和类型).
   类或者结构中的index隐藏了基类中具有相同签名的index(参数个数和类型)
   操作符的声明规则使得不可能在派生类中声明一个具有和基类同样签名的操作符.所以,操作符永远不会相符覆盖.
4-9章分别介绍类型,变量,转换,表达式,语句和命名空间.这些部分内容就不再看了.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#nameof用法发布时间:2022-07-14
下一篇:
C#语言和运行时剖析--前言发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap