一、深拷贝与浅拷贝
浅拷贝(Shallow copy):拷贝对象引用,指向同一对象
深拷贝(Deep copy):创建对象副本
二、值类型与引用类型
值类型分配在栈上,引用类型分配在堆(Managed heap)上
Struct是值类型,但是如果Struct的成员是引用类型,则成员依旧遵循浅拷贝语义。(两个Struct对象包含同一个引用类型成员)
三、Const与Readonly
Const在编译期初始化,Readonly在运行时初始化
四、new与override
(我理解) 编译器确定与运行期确定
五、可达性与可见性
Class aBase { public string s ; }
Class aDerived : aBase { new private string s ;}
Class aMostDerived : aDerived { public void foo { string str } { s = str ; }
在C++中会报错(先考虑可达,后考虑可见),C#中(先考虑可见,后考虑可达),会改变aBase中的s,因为aDerived 中的s是private。
六、接口与抽象类
接口不提供缺省实现或是任何“状态”
七、System命名空间
Environment Class :可以取得用户姓名、机器名及操作系统相关信息
Process Class:有2个static拣取函数GetCurrentProcess()和GetProcess()
System.IO:
1.Path Class:处理文件扩展名
2.Stream Class:
Stream的Read函数接受3个参数,第一个用以存放被读取的Bytes array,
第二个指明从Bytes array的哪个位置开始置入内容,第三个表明希望读取的最大
bytes数。返回的是实际读取的bytes个数,0表示达到末尾。
Stream的Read函数接受3个参数,第一个是待被写出的Bytes array,
第二个指明从Bytes array的哪个位置开始写出,第三个表明希望写出的bytes数。
FileInfo ifd = new FileInfo( inFile );
FileInfo ofd = new FileInfo( outFile );
Stream ifile = ifd.openRead();
Stream ofile = ofd.openWrite();
const int max_bytes = 124;
byte[] buffer = new byte[ max_bytes ];
int bytesRead;
while (( bytesRead = ifile.Read( buffer , 0 , max_bytes )) != 0 )
{
Console.WriteLine( " Bytes read: {0}", bytesRead );
ofile.Write( buffer, 0, bytesRead );
}
System.Collection : System.Collection.Stack & System.Collection.Queue.
System.Diagnostics : 此命名空间提供了一整族的TraceListener class,利用他们,用户
可以开启并控制诊断信息的输出。
Trace.WriteLine()表示向主控监视机关(某个Listensers)输出信息。
如果用户已向Trace中的 Listeners群集添加了某个监视设备(译注:例如添加
了TextWriterTraceListenser),则WriteLine() 的输出被导至该处.
无论在Debug或Release模式,总会开启追踪器。 如果想在Release中
消除这些起追踪作用的程序代码,可利用Debug class代替Trace class。
八、正则表达式:
/d 匹配单个数字 , /D 匹配非数字字符。 /s 匹配空白字符, /S 匹配非空白字符。
/w 匹配任意文本数字(alphanumeric,字母,下划线, 数字) ,/W 匹配任何非文数字(标点,空白等)
Regex regex = new Regex( filter ) ;
Match match = regex.Match( inputString );
if(!match.Success) { ... }