委托,多播

  1. 多播委托的时候:拿到的返回值是最后一个一个委托指向的方法的执行结果    创建委托:delegate int Adddel(int a,int b);    Adddel del=new Adddel(实例方法名);  不要用了
  2. Func<int,int> funcdemo=new func<int,int>(方法名);  泛型委托 可以最多有16个参数的重载,最后一个参数永远都是返回值  俩个参数一个返回值 

修正:第一个参数标识返回类型,第二个以后的为参数列表

简化泛型匿名方法:Func<int,int,int> funcdemo=delegate(int a ,int b){return a+b;}

继续简化→labmda语句:Func<int,int,int> funcdemo=(int a,int b)=>{return a+b};

继续简化→labmda表达式:Func<int,int,int> funcdemo=(int a,int b)=>a+b;

继续简化→labmda 表达式:Func<int,int,int> funcdemo=(a,b)=>a+b;

微软定义的俩个泛型:Func有返回值   Action无返回值

左侧为要输入的参数,右侧为要求值的表达式或方法体

  1. 读取文件System.IO;

OpenFileDialog ofd=new OpenFileDialog();using

If(ofd.showDialog()!=system.windows.forms.DialogResult.OK){return;}

FilesStream  fs=new FileSteam(ofd.filename,FileModel.Open,FileAccess.Read)using

{

Streamreader sr=new steamreader(fs)

{   while(!st.endofstream)但读取器不为最后一行的时候,否则就跳出循环

{string line=sr.readerline()}

}

保存saveFileDialog sfd=new SaveFileDialog(); 

If(sfd.showDialog()!=system.windows.forms.DialogResult.OK){return;}

Streamwrite sw=new streamwtite(sfd.filename,false,encoding.default,1024*1024);

Sw.write(string);sw.flush();

或者

FileSteam fs=new FileSteam(sfd.fileName,filename.openorcrate,fileAccess.readWrete)

{  string txt=要写的字符串.replace(“ ”,” ”); byte[]data=encoding.defalut.getBytes(txt);

Fs.write(data,0,data.length);}

原文地址:https://www.cnblogs.com/jinhaoObject/p/4542929.html