• C# Programming Language学习笔记(二)


     第一章 概述
    1.Struct constructors are invoked with the new operator, but that does not imply that memory is being allocated. Instead of dynamically allocating an object and returning a reference to it, a struct constructor simply returns the struct value itself (typically in a temporary location on the stack), and this value is then copied as necessary.
    结构的构造器用new操作符调用,但是这并不意味着内存的分配(译注:很奇怪,难道allocate特指堆上的内存分配?)不是动态地分配一个对象并返回指向该对象的引用,结构的构造器只是返回结构的值本身(典型地,返回栈上的一个临时位置),在必要时这个值被复制
    2.C# also supports multi-dimensional arrays. The number of dimensions of an array type, also known as the rank of the array type, is one plus the number of commas written between the square brackets of the array type. The following example allocates a one-dimensional, a two-dimensional, and a three-dimensional array.
    C#支持多为数组.数组类型的维数,也被称为数组类型的层级,是数组类型中中括弧内的逗号的个数加1.
    下面的例子分配了一个一维数组,一个二维数组和一个三维数组

    int[] a1 = new int[10];

    int[,] a2 = new int[105];

    int[,,] a3 = new int[1052];

    3.The element type of an array can be any type, including an array type. An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same. The following example allocates an array of arrays of int.
    数组元素可以为任意类型,包括数组类型.元素为数组类型的数组有时称为锯齿形数组,因为元素数组的
    长度不必具有相同的长度.下面的例子是一个整型数组(作为数组元素)的数组.

    int[][] a = new int[3][];

    a[
    0= new int[10];

    a[
    1= new int[5];

    a[
    2= new int[20];

    4.C# also supports explicit interface member implementations, using which the class or struct can avoid making the members public. An explicit interface member implementation is written using the fully qualified interface member name.Explicit interface members can only be accessed via the interface type.
    C#也支持显式接口成员实现,这样类和结构可以避免成员public.显式接口成员的实现用全名称引用接口成员的名字.
    显式接口成员只能通过接口类型访问.
    (译注:人这个类想实现一些包含某些方法的接口,这个接口中有吃喝拉撒,还有驾驶神州六号这个方法,但是并不是每个人都有机会去驾驶神州六号.但是有没有其它接口只能实现这个接口,怎么办那?这时可以用显式接口的方法,这个方法只能在将人这个类转换成接口的时候才能调用该方法).
    5.An enum type's storage format and range of possible values are determined by its underlying type. The set of values that an enum type can take on is not limited by its enum members. In particular, any value of the underlying type of an enum can be cast to the enum type and is a distinct valid value of that enum type.
    枚举类型的存储格式和取值范围由底层类型决定.枚举类型可以具有的值集合(译注:即枚举类型的取值范围)
    不受枚举成员的限制.特别地,枚举的底层类型的任意值都可以转化成枚举类型并且是枚举类型独特的有效值.
    6.In order for the default value of an enum type to be easily available, the literal 0 implicitly converts to any enum type. Thus, the following is permitted.
    为了容易地利用枚举类型的默认值,0隐含地转化为任意的枚举类型.因此下面(译注:的语句)是允许的.

    Season spring = 0;

    7.A delegate that references an instance method also references a particular object, and when the instance method is invoked through the delegate, that object becomes this in the invocation.
    引用某个实例方法的委托同时也引用一个特定的对象,并且当方法通过该委托调用时,这个对象在用this(表示)
    8.An interesting and useful property of a delegate is that it does not know or care about the class of the method it references; all that matters is that the referenced method has the same parameters and return type as the delegate.
    委托的一个有趣且有用的特性是它不知道或者关心它引用的方法所在的类;它所关心的仅仅是它引用的方法和委托有相同的参数和返回类型.
    9.Types, members, and other entities in a C# program support modifiers that control certainaspects of their behavior. For example, the accessibility of a method is controlled using the public, protected, internal, and private modifiers. C# generalizes this capability such that user-defined types of declarative information can be attached to program entities and retrieved at runtime. Programs specify this additional declarative information by defining and using attributes.
    C#中的类型,成员和其它实体支持可以控制他们行为各个方面的修饰符,比如,方法的可见性publicprotected,internal和private修饰符来控制.C#推广了这个能力,于是用户自定义的声明信息可以附加到程序实体并在运行时获取到.程序通过定义和使用属性指定附加的声明信息.
    10.All attribute classes derive from the System.Attribute base class provided by the .NET Framework. If an attribute's name ends in Attribute, that part of the name can be omitted when the attribute is referenced
    所有的属性类都继承自.NET Framework提供的System.Attribute这个基类.如果属性的名字以Attribute结尾,当属性被引用是Attribute可以省略.

  • 相关阅读:
    Linux 关机和重启命令
    Linux ubuntu安装ftp服务器
    C++ map和unsorted_map底层实现
    C++中的那些容器在使用时,哪些情况下迭代器会失效
    虚函数表的构造
    C++容器 priority_queue,堆的实现
    c++11中的move是否会改变对象的地址
    (转)关于linux中内核编程中结构体的赋值操作(结构体指定初始化)
    无参方法
    类和对象
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/257717.html
Copyright © 2020-2023  润新知