The Programming Language Tips[7]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 chelsea 的 blog

     file file("auto.txt");

     char buf[256];

     fread(buf, 0, 256, file);//即使这个操作会抛出异常,文件依然会被关闭

}

[c#,仅仅示例]

     public class file:idisposable { 

         private filestream fs; 

         public file(string path){

              fs = new filestream(path, filemode.create);

         } 

         public static implicit operator filestream(file file) {

              return file.fs;

         } 

         public void dispose() {

              fs.close();

         }

     }

[c#,仅仅示例]

     public class test{

         void test(){

              using(file file = new file("auto.txt")){

                   //some read, write, etc.

本文关键:The Programming Language Tips
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top