C#复习⑨(附带C#参考答案仅限参考)

C#复习⑨

2016年6月22日

14:28

C#考试题&参考答案:http://pan.baidu.com/s/1sld4K13

Main XML Comments & Pointer XML注释和指针

1.Special Comments

注释很重要!!!

clip_image001

clip_image002

2.XML Tags

有那么些类似于HTML的标签

Predefined Tags

Main tags

<summary> short description of a program element </summary>

<remarks> extensive description of a program element </remarks>

<example> sample code </example>

<param name="ParamName"> description of a parameter </param>

<returns> description of the return value </returns>

<exception [cref="ExceptionType"]> used in the documentation of a method:
describes an exception </exception>

Part of other descriptions

<code> multi-line code pieces </code>

<c> short code pieces in the text </c>

<see cref="ProgramElement"> name of a crossreference link </see>

<paramref name="ParamName"> name of a parameter </paramref>

3.Pointer Types

举例:

int*        ip;        // 指向int类型的指针

MyStruct*        sp;        // 指向MyStruct的指针

void*        vp;        //执行内存任何位置的指针

int**        ipp;        // 指向一个int指针的指针

clip_image004

指针与引用的不同:

指针不能被垃圾回收机制追踪;

指针类型不能与System.Object不兼容!!!

曾有判断题:All types are compatible with object (False)

指针其他特点:

指针可以赋予空值null;

指针可以进行通过(==、!=、<、<=、>、>=)相互比较

4.Unsafe Code不安全的代码

使用指针的代码被称为不安全的代码

clip_image005

使用指针:

clip_image006

5.Pinned and Unpinned Variables

Pinned:

不能被垃圾回收机制回收;

cannot be moved by the garbage collector (anything which is on the stack)

局部变量;

local variables

值参数;

value parameters

固定结构域

fields of pinned structs

Unpinned:

可以被垃圾回收机制回收;

can be moved by the garbage collector (anything which is on the heap)

类或者static域;

fields of classes (also static fields)

数组元素;

array elements

ref或者out修饰的参数

ref and out parameters

6.Address Operator & fixed Statement 固定语句

&取值操作符!

执行期间固定一个不固定的变量;

Pins an unpinned variable during the execution of this statement

clip_image008

clip_image009

clip_image010

8.Dangers of Pointer Processing

可以破坏任意内存位置;

可以留下来指向对象(但是对象已被垃圾收集移动对象)的指针;

一个可以用指向非现有的局部变量的指针;

避免指针处理!

clip_image012

clip_image013

 

原文地址:https://www.cnblogs.com/zpfbuaa/p/5607158.html