(部分伪)面向对象视频笔记

来源:互联网 发布:个人域名备案企业网站 编辑:程序博客网 时间:2024/06/08 07:53

 

扩展方法

 

 

先声明一个静态类

再声明一个静态方法

 

String str ;

str.ToInt32();

 

Public static class StringExtend

{

Public static int ToInt32(this string str)

 

{ return int.Parse(str);

 

}

}

 

 

 

委托

 

 

Action 无返回值

Fun<T> 有返回值

 

 

Action<int,int> add = Add1;//表示两个参数

 

add += Add2;

 

add(1,2);

 

 

Fun<int,int> add = Add2;//表示一个参数,一个返回值,最后一个参数为返回值。

 

 

 

 

 

 

委托方法

 

Static void DealString(Fun<string , string> dealFun,string str)

{

dealFun(str);

 

}

 

委托调用

 

DealString(ToUpper,"abc");

 

 

 

 

线程

 

 

Thread thread1 = new Thread(Write1);//声明线程

 

//是否后台

thread1.IsBackground = true; //主线程退出了,此线程也退出。

 

thread1.Start(); //开启线程

 

Static void Write1()

{

Lock("asdf")//多种线程访问需要加锁

{

 

}

Cw….

 

}

 

 

 

 

 

 

单例模式

 

为了让当前只存在一个当前对象

 

 

 

 

工厂模式

 

简单

 

 

 

调用

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

子弹

 

当内存不够用的时候,销毁的东西的内存,才会被回收。

 

 

 

 

调用

 

 

 

订阅模式