c# 随笔
来源:互联网 发布:阿里云 idc报告 编辑:程序博客网 时间:2024/05/19 12:15
匈牙利标记法、camel命名法、Pascal命名法
decimal decimal coin = 0.42M
以*.sln为打开链接,一个.sln可以包含多个.csproj
infinity 无穷大 0*infinity=0
NaN not a number
0*NaN=NaN
NaN*infinity=infinity
组件 component
optMethod(first:99,third:"world");optMethod(99,third:"world");
试图引用没有初始化的数据不能通过编译
C#里面没有指针的概念
结构和类的主要区别
structSample? aStructSample = null
public override string ToString(){ string data = String.Format("{0} {1} {2}",this,month,this.day,this.year); return data;}
结构不能自定义复制构造函数,类没有复制构造函数,因为类是引用类型
int[] array1;array1 = new int[4];int size = int.Parse(Console.ReadLine());int[] array2 = new int[size];
int[] array = new int[3]{1,2,3,4}; //编译时错误int[] array = new int[4]{1,2,3}; //编译时错误int[] array = new int[4]{1,2,3,4}; //正确int[] array = {1,2,3,4}; //正确var names = new[]{"John","Paul","James"} //正确,其中names.Length的值为3var bad =new[]{"John","Paul",1993} //正确,1993自动转换为字符串型 foreach (int i in array){ ... //此处不能通过i修改数组元素的值,i是副本}
int[] pins = {1,2,3,4};int[] copy =new int[pins.Length];pins.CopyTo(copy,0);
int[] pins = {1,2,3,4};int[] copy = new int[pins.Length];Array.Copy(pins,copy,copy.Length);
int[] pins = {1,2,3,4}int[] copy = (int[])pins.Clone();
int[,] items = new int[4,6];
抽象类和接口的区别
抽象类不能被实例化,而接口可以实例化来指向实现它的类(多态的体现)
所以在C++中 没有接口的设计 但是用抽象类代替了接口的功能
垃圾回收器的工作原理
垃圾回收器在它自己的线程中运行,而且只有在特定的时候才会执行(通常是应用程序抵达一个方法的结尾的时候)。它运行时,应用程序中运行的其它线程将暂停。这是由于垃圾回收器可能需要移动对象并更新对象引用;假如对象仍在引用,就不能进行这些操作。
垃圾回收器采取的步骤如下:
- 它构造包含所有可达对象的一个映射表map。为此,它会反复跟随对象中的引用字段。垃圾回收器会非常小心地构造这个map,并确保循环引用不会造成无限递归。任何不在这个map中的对象肯定是不可达的。
- 它检查是否有任何不可达的对象含有一个需要运行的析构器(运行析构器的过程称为finalization 或者说“终结”)。需要终结的任何不可达的对象都会放到一个特殊的队列中。这个队列称为freachable(发音是F-reachable)队列。
- 它回收剩余的不可达对象(即不需要终结的对象)。为此,它会在堆(heap)中向下移动可抵达的对象,从而对heap进行“碎片整理”,并释放位于heap顶部的内存。垃圾回收器移动了一个可达的对象后,还会更新该对象的任何引用。
- 然后,它允许其它线程恢复运行。
- 它在一个单独的操作中,对需要终结的不可达对象(现在,这些对象在freachable队列中了)执行finalize操作。
慎用析构器
索引器
索引可用于接口、类、结构体中
struct IntBits{ ... public bool this [int index] //整型index作为索引,返回bool型值 { get { return (bits & (1 << index)) !=0; } set { if (value) bits |= (1 << index); else bits &= ~(1 << index); } } ...}
struct Wrapper{ private int[] data; ... public int this [int i] //整型i作为索引,返回int型值 { get { return this.data[i]; } set { this.data[i] = value; } }}
委托
class Controller{ delegate void stopMachineryDelegate(); private stopMachineryDelegate stopMachinery; ... public Controller() { this.stopMachinery += folder.StopFolding; } ... public ShutDown() { this.stopMachinery(); ... }}
Controller control = new Controller();FoldingMachine folder = new FoldingMachine();WeldingMachine welder = new WeldingMachine();PaintingMachine painter = new PaintingMachine();...control.Add(welder.FinishWelding);control.Add(painter.PaintOff);...control.ShutDown();...
适配器
void FinishFolding(){ folder.StopFolding(0);}
将lambda 表达式作为适配器使用
this.stopMachinery += (() => { folder.StopFolding(0); });
this.stopMachinery += (() => folder.StopFolding(0));
0 0
- C#随笔
- C#随笔
- c#随笔
- c# 随笔
- C# Dev 随笔记录
- COOKIES 随笔 C#
- C# 知识点随笔
- C#学习随笔
- C# linq 随笔参考
- C#反射Reflection学习随笔
- 随笔2 - C#的JSON
- C#中 Oracle实用随笔
- 2007.08.23 C#工作随笔
- 2007.08.24 C#工作随笔
- 《C#类设计手册》读书随笔
- C#程序集Assembly学习随笔
- c# 随笔------Dictionary泛型的使用
- 随笔C#中的事件和委托
- 【BZOJ2466】【中山市选2009】树 高斯消元解异或方程组
- http://www.ebay.de/cln/hkrwr-mlkpoc9a/2015-03.17/189018409012
- 蚁群算法解决TSP问题的JAVA实现(一)
- JAVA操作properties文件
- 黑马程序员--c语言-计算机中的进制
- c# 随笔
- uva 674 Coin Change
- Linux加锁机制整理
- C#利用tabControl控件实现多窗体嵌入及关闭
- 回文数
- rutydiezrswrs生日主题度日ur事业
- POJ 3660 Cow Contest (Floyd 传递闭包)
- Linux线程调度
- 薈蚀羇芁莈薃羂肇芇薅肈膆