日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

必知必會的40個C#語言方面的技術(shù)細(xì)節(jié)

 悟靜 2012-11-18

細(xì)節(jié)01給C#代碼加注釋的意義
細(xì)節(jié)02裝箱和拆箱
細(xì)節(jié)03理解值類型和引用類型

值類型變量不能為null,必須具有一個確定的值。引用類型被賦值前的值都是null
細(xì)節(jié)04隱式轉(zhuǎn)換和顯示轉(zhuǎn)換
細(xì)節(jié)05前綴方式增1和減1運算符
細(xì)節(jié)06理解移位運算符
>>運算符將第一個操作數(shù)向右移動第二個操作數(shù)所指定的位數(shù)
<<運算符將第一個操作數(shù)向左移動第二個操作數(shù)所指定的位數(shù)
注意幾點:
1.如果第一個操作數(shù)為int或uint,則移位數(shù)由第二個操作數(shù)的低五位給出
2.如果第一個操作數(shù)為long或ulong,則移位數(shù)由第二個操作數(shù)的低六位給出
例如:int i; i=48>>3 則i=6
48對應(yīng)的二進(jìn)制為00110000,右移3位后的二進(jìn)制值為00000110,則十進(jìn)制為6
細(xì)節(jié)07理解運算的次序
細(xì)節(jié)08理解參數(shù)的類型

輸入?yún)?shù),輸出參數(shù)out,引用參數(shù)ref,參數(shù)數(shù)組params
細(xì)節(jié)09重載方法
細(xì)節(jié)10虛方法與重寫方法

虛方法指允許被其子類重新定義的方法,在聲明時需要用virtual修飾符
重寫也稱為覆蓋override,是在派生類使用override修飾符重寫基類中帶有virtual修飾符的虛方法
注意:override修飾符不能與new,static,或virtual修飾符同時使用
,另外,重寫方法只能用于重寫基類中的虛方法,不能用來單獨聲明方法。
派生類中使用new關(guān)鍵字可以實現(xiàn)向基類成員隱藏繼承成員。
public class Child:Parent
{
  public new string m()
{return "隱藏一般方法"}
}
細(xì)節(jié)11結(jié)構(gòu)和類的區(qū)別
細(xì)節(jié)12什么是封裝
細(xì)節(jié)13什么是繼承
細(xì)節(jié)14什么是多態(tài)
細(xì)節(jié)15作用域的概念
細(xì)節(jié)16使用索引器

索引器就是能夠讓類像一個數(shù)組似的被訪問。索引器與屬性很相似,也有g(shù)et和set訪問器。
public string this[int Ind]
{
  get
{}
}
shapeName=s[Count];
細(xì)節(jié)17base和this關(guān)鍵字
base關(guān)鍵字用于派生類中訪問基類的成員。使用范圍如下:
1.調(diào)用基類中已被其他方法重寫的方法
2.指定創(chuàng)建派生類實例時應(yīng)調(diào)用的基類構(gòu)造函數(shù)。
細(xì)節(jié)18理解靜態(tài)修飾符
細(xì)節(jié)19。net的object類

System.Object類的核心成員如下:
Equals():確定兩個object實例是否相等
Finalize():釋放資源并執(zhí)行其他清理操作。
GetHashCode():返回一個能夠標(biāo)識內(nèi)存中指定對象的整數(shù)
GetType():獲取當(dāng)前實例的System.Type()對象
MemberwiseClone():返回當(dāng)前對象逐個成員的副本
ToString()
細(xì)節(jié)20細(xì)說可空類型
在訪問數(shù)據(jù)庫數(shù)據(jù)時可能獲得的數(shù)據(jù)為空值,這時可以考慮使用可空類型來定義字段或方法以更好的使用類來操作數(shù)據(jù)。
int?i=null;
int?等價于System.Nullable<int>
細(xì)節(jié)21分部類
public partial class Person
{}
開發(fā)分部類時,要成為同一類型的各個部分的所有分部類類型定義必須都在同一個程序集或者同一??熘小#?。exe或dll)中進(jìn)行定義,分部類定義不能跨越多個模塊。
細(xì)節(jié)22匿名方法
匿名方法:在事件注冊時直接將一個委托與一段代碼相關(guān)聯(lián),這種代碼就是匿名方法。
Sendbtn.Click+=delegate{"sda"};定義委托的后面要加上分號。
delegate void Msg(string str)//定義委托
public void GetMsg(string str)//定義與關(guān)聯(lián)委托匹配的方法
{Response.Write("dads");}
Msg d =delegate(string str){Response.Write(str);}//委托與匿名方法的關(guān)聯(lián)
Msg d= new Msg(GetMsg);//委托與命名方法關(guān)聯(lián)
Sendbtn.Click+=delegate{Response.Write("safsaf");};//事件處理程序為匿名方法
細(xì)節(jié)23。net框架提供的屬性(attribute)
。net框架提供了內(nèi)置屬性,這些屬性都是從System.Attribute類派生而來的。
Conditional屬性是System.Diagnostics.ConditionalAttribute的別名,該屬性僅用于方法聲明,即僅在C#編譯器定義了作為屬性參數(shù)出現(xiàn)的符號時,他才指定方法作為類的一部分
[Conditional(“參數(shù)”)]
啟用調(diào)試狀態(tài)時才作為類的一部分可以被調(diào)用,
Obsolete屬性用于定義正被替換或者不再有效的代碼。該屬性有兩個參數(shù)Message和IsError,Message用于設(shè)置錯誤信息字符串,IsError默認(rèn)為false表示在編譯代碼時發(fā)出警告信息,True表示編譯器將生成錯誤信息。
細(xì)節(jié)24自定義屬性類(Attribute)
自定義屬性類派生于System。Attribute類

自定義屬性類的特定:

1.使用AttributeUsage屬性可以限制屬性的用法。

2.在AttributeUsage屬性中可以指定是否可以多次使用屬性。

3.可以設(shè)置屬性參數(shù)。

    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]//AttributeTargets.Class表示限制僅用于類。 AllowMultiple = true表示可以多次使用屬性
    public class BookAttribute : Attribute
    {
        private string BookName;
        public BookAttribute(string bookname)//設(shè)置屬性參數(shù)
        {
            this.BookName = bookname;
        }
        public string Book
        {
            get
            {
                return BookName;
            }
        }
    }
    //多次使用屬性類
    [Book("細(xì)說ASP.NET;")]
    [Book("范例手冊")]
    public class BookInfo
    {
        public string binfo = "圖書信息-------";
        public BookInfo() { }
    }

     protected void Page_Load(object sender, EventArgs e)
        {
            BookInfo bf = new BookInfo();
            object[] Bookattr;
            System .Reflection .MemberInfo  Typeinfo=typeof (BookInfo );
            //提取類型是屬性類的成員
            Bookattr = Typeinfo.GetCustomAttributes(typeof (BookAttribute ),false );
            if (Bookattr.GetLength(0) != 0)
            {
                BookAttribute ba = (BookAttribute)Bookattr[0];//獲取屬性類的第一個成員
                BookAttribute ba2=(BookAttribute )Bookattr [1];//獲取屬性類的第二個成員
            }

}
細(xì)節(jié)25泛型
細(xì)節(jié)26包含/委托
類似適配器模式,把類中定義對象,然后自定義方法,然后在方法體中用到定義的對象中的方法。
細(xì)節(jié)27實現(xiàn)迭代器
迭代器是可以返回相同類型值的有序序列的一段代碼,可用做方法、運算符或get訪問器的代碼體??梢栽陬愔袑崿F(xiàn)多個迭代器,每個迭代器都必須像類成員一樣有唯一的名稱。并且可以再foreach語句中被客戶端代碼調(diào)用。迭代器的返回類型必須為IEnumerable或IEnumerator中任意一種,也可以是實現(xiàn)這兩個接口的類。
IEnumerable接口:包含了。net框架用于從對象中提取元素的方法。如果類包含一個元素的集合,并希望其他代碼段使用foreach循環(huán)語句遍歷該集合中的每一個元素則應(yīng)該在類上實現(xiàn)該接口。
IEnumerable接口值包含一個方法定義GetEnumerator(),用于返回一個循環(huán)訪問集合的枚舉數(shù)。
IEnumerator接口:支持對非泛型集合的簡單迭代。該接口定義了一個屬性和兩個方法
1.Object Current{get}屬性,獲取集合中的當(dāng)前元素
2.bool MoveNext()方法,訪問集合的下一個元素
3.void Reset()方法,設(shè)置枚舉數(shù)為其初始位置。
使用時必須引用System。Collection命名空間
public class Car : IEnumerable, IEnumerator
    {
        private short flag = -1;
        public IEnumerator GetEnumerator()
        {
            return  this;
        }
        public object Curretn
        {
            get
            {
                switch (flag)
                {
                    case 0:
                        return "aodi";
                    case 1:
                        return "huangguan";
                    default :
                        return "this is Error";
                }
            }
        }
        public bool MoveNext()
        {
            flag++;
            if(flag ==2)
            {
                return false;
            }
            return true;
        }
        public void ReSet()
        {
            flag = -1;
        }
    }
 static void Main(string[] args)
        {
            Car car = new Car();
            foreach (string s in car)
            {
                Response.Write(s+"</br>");
            }
        }
使用C#中的yield return命令也可以實現(xiàn)迭代器
細(xì)節(jié)28壓縮和解壓縮流的方法
在。net中,systtem.Io.Strem 類是所有流類型的虛基類。操作文件的FileStrem,操作內(nèi)存的MemoryStrem操作網(wǎng)絡(luò)的NetworkStrem
Stream類的Read()方法用于從當(dāng)前流中讀取字節(jié)序列。
public abstract int Read()
{
  byte[] buffer,//字節(jié)數(shù)組
  int offset,//表示從開始讀取的位置
  int count//讀取的最大字節(jié)數(shù)
}
Stream類的Write()方法用于從當(dāng)前流中寫入字節(jié)序列。并返回寫入的字節(jié)數(shù)
public abstract int Write()
{
  byte[] buffer,//字節(jié)數(shù)組
  int offset,//表示從開始寫入的位置
  int count//寫入的字節(jié)數(shù)
}
一般情況下,對文件或數(shù)據(jù)可以進(jìn)行壓縮或解壓縮操作。實質(zhì)上就是對流的操作。在。net框架的System.IO.Compression命令空間下提供了GZipStream類,可以實現(xiàn)對流的壓縮和解壓縮。
public GZipStream
(
  Stream stream;//要壓縮或解壓縮的流
  CompressionMode mode;//要采取的操作(Compress壓縮流或Decompress解壓縮流)
  bool leaveOpen (true表示將流保留為打開狀態(tài),false表示流為關(guān)閉狀態(tài))
)
 //定義一個用于讀取指定數(shù)據(jù)流中的數(shù)據(jù)的方法
        private const int bufferlength=1024;
        public static Byte[] ReadBytes(Stream stream, int bufferlength)
        {
           Byte[]buffer=new Byte  [bufferlength ];
           List<Byte> data = new List<Byte>();
           int real;
           while ((real = stream.Read(buffer, 0, bufferlength)) > 0)
           {
               if (real < bufferlength)
               {
                   Byte[] temp = new Byte[real];
                   Array.Copy(buffer, temp, real);
                   data.AddRange(temp);
               }
               else
               {
                   data.AddRange(buffer );
               }
           }
           return data.ToArray();
        }
         //定義一個向當(dāng)前流中寫入字節(jié)數(shù)組數(shù)據(jù)
        public static void WriteBytes(Stream stream, Byte[] data, int bufferlength)
        {
           Byte[]buffer=new Byte[bufferlength ];
           for (long g = 0; g < data.LongLength; g += bufferlength)
           {
               int le = bufferlength;
               if (g + bufferlength > data.LongLength)
               {
                   le=(int)(data.LongLength -g);
               }
               Array.Copy(data,g,buffer,0,le );
               stream.Write(buffer,0,le );
           }
        }
        //自定義方法壓縮流,并調(diào)用前面定義的方法
        //壓縮字節(jié)數(shù)據(jù)
        public Byte[] CompressByte(Byte[] data)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                //提供壓縮內(nèi)存流的方法
                using (System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(ms, CompressionMode.Compress, true))
                {
                    WriteBytes(gs,data,bufferlength );//將數(shù)據(jù)寫入壓縮流
                }
                return ms.ToArray();//返回壓縮后的數(shù)據(jù)
            }
        }
        //自定義方法解壓縮流
        public static Byte[] DeCompressByte(Byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data ))//數(shù)據(jù)存于內(nèi)存流
            {
                //提供解壓縮的方法
                using (System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(ms, CompressionMode.Decompress, true))
                {
                    return ReadBytes(gs, bufferlength);//讀取解壓縮流中的數(shù)據(jù)
                }
               
            }
        }
細(xì)節(jié)29C#中的深復(fù)制和淺復(fù)制
淺復(fù)制是指復(fù)制一個對象的時候,復(fù)制原始對象中所有的非靜態(tài)值類型成員和所有的對應(yīng)類型成員的引用
深復(fù)制是指不僅僅復(fù)制所有的非靜態(tài)值類型成員,而且還復(fù)制所有引用類型成員的實際對象。
細(xì)節(jié)30全角字符轉(zhuǎn)換為半角
全角字符是指一個字符占用兩個標(biāo)準(zhǔn)字符位置。
半角字符是指一個字符占用一個標(biāo)準(zhǔn)字符的位置。
 //判斷字符是否英文半角字符或標(biāo)點
        public static bool IsHalflChar(char c)
        {
            int i = (int)c;
            return i >= 32 && i <= 126;

        }
        //判斷字符是否全角或標(biāo)點
        public static bool IsAllChar(char c)
        {
            if(c=='\u3000')return true ;
            int i =(int )c-65248;
            if (i < 32) return false;
            return IsHalflChar((char)i);

        }
        //將字符串中的全角字符轉(zhuǎn)換和為半角
        public static string aToh(string s)
        {
            if(s==null ||s.Trim ()==string.Empty )return s;
            StringBuilder sb = new StringBuilder(s.Length );
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '\u3000') { sb.Append('\u0020'); }
                else if (IsAllChar(s[i])) { sb.Append((char)((int)s[i] - 65248)); }
                else
                    sb.Append(s[i]);
            }
            return sb.ToString();
        }
細(xì)節(jié)31分析路徑字符串函數(shù)總結(jié)
相對路徑:指相對對于網(wǎng)站地址的文件路徑。
絕對路徑:指磁盤上的一個指定位置。
C#中通過Path類的相關(guān)方法可以分析路徑字符串。
GetDirectoryName:返回指定路徑字符串的目錄信息
GetExtension:返回指定的路徑字符串的擴展名
GetFullPath:返回指定路徑字符串的絕對路徑
GetPathRoot:獲取指定路徑的根目錄信息
HasExtension:確定路徑是否包含文件擴展名
IsPathRooted:獲取一個值,該值指示指定的路徑字符串是包含絕對路徑信息true還是包含相對路徑信息false。
 //分析路徑字符串
        protected void FenSi()
        {
            string str = string.Empty;
            string path1 = "c:\\temp\\blog.txt";
            string path2 = @"c:\\temp\\blog";
            string path3 = @"Record";
            if (Path.HasExtension(path1))
            {
                str = string.Format("路徑{0});下有一擴展名為{1}的文件,屬于目錄{2}", path1, Path.GetExtension(path1), Path.GetDirectoryName(path1 ));
            }
            if (Path.IsPathRooted(path2))
            {
                string.Format("路徑{0}的根目錄為{1}",path2 ,Path .GetPathRoot (path2));
            }
            str = string.Format("路徑{0}的全路徑為{1}",path3,Path .GetFullPath (path3));
        }
細(xì)節(jié)32重載一元。二元運算符
細(xì)節(jié)33對象也能排序

System.Array類提供的Sort()靜態(tài)方法可以根據(jù)數(shù)字、字母順序?qū)?shù)組中的項進(jìn)行排序。
System.ICompareTo()接口指定了一種允許一個對象可基于某些特定鍵值進(jìn)行排序的方法。該接口提供一個CompareTo()方法用于比較當(dāng)前實例與同一類型的另一個對象。
返回值小于0表示當(dāng)前實例小于另一個對象。
 public class Student : IComparable
    {
        private int sid;
        public string name;
        public Student(int sid, string name)
        {
            this.sid = sid;
            this.name = name;
        }
        public int ID
        {
            get{return sid;}
            set { sid = value; }
        }
        int IComparable.CompareTo(object obj)
        {
            Student s = (Student)obj;
            if (this.sid > s.sid)
            {
                return 1;
            }
            if (this.sid < s.sid)
            {
                return -1;
            }
            else
                return 0;
        }
    }
string str = string.Empty;
            Student []arr=new Student [4];
            arr[0] = new Student(65,"張三");
            arr[1] = new Student(62, "張三");
            arr[2] = new Student(63, "張三");
            arr[3] = new Student(63, "張三");
            Array.Sort(arr);//對象排序
            foreach (var item in arr)
            {
 
            }
細(xì)節(jié)34實現(xiàn)IDisposable接口清除對象
利用。net框架提供的方法處理非內(nèi)存資源,也就是通過實現(xiàn)IDisposable接口來釋放非托管的資源。
IDisposable接口:它的Dispose()方法用于執(zhí)行與釋放或重置非托管資源相關(guān)應(yīng)用程序定義的任務(wù)。
為using語句提供的對象必須實現(xiàn)IDisposable接口,此接口提供了Dispose()方法,該方法釋放資源。
public class Test : IDisposable
    {
        public Test()
        { Console.WriteLine("a"); }
        ~Test()
        { Console.WriteLine("b"); }
        public void Dispose()
        {
            Console.WriteLine("c");
        }
    }
 static void Main(string[] args)
        {
            try
            {
                using (Test te = new Test())
                {
                    throw new Exception("safaf");
                }
            }
            catch { }
        }
運行結(jié)果:
a
c
b
細(xì)節(jié)35將字符串轉(zhuǎn)成字符數(shù)組
。net框架在System.IO命名空間下的StringRead類可以實現(xiàn)把字符串轉(zhuǎn)換為字符數(shù)組
StringRead類的Read()方法用于讀取輸入字符串中的字符快
public override int Read()
{
  char[] buffer,//讀取到的字符數(shù)組
  int index,//表示從開始讀取的位置
  int count//要讀取的字符數(shù)
}
  //將字符串轉(zhuǎn)換為字符數(shù)組
        protected void ZhuanHuan()
        {
            string str = "are you Read";
            char[]c=new char[200];
            StringReader sr = new StringReader(str);
            sr.Read(c,0,19);
        }
細(xì)節(jié)36將字符數(shù)組寫入到字符串
StringBuider類和StringWriter類可以實現(xiàn)
public override int Read()
{
  char[] buffer,//讀取到的字符數(shù)組
  int index,//表示從開始讀取的位置
  int count//要讀取的字符數(shù)
}
 //將字符數(shù)組寫入字符串
        protected void Zhuan()
        {
            StringBuilder sb = new StringBuilder("One World");
            char[] c = { '.','0','n','e','c','d',};
            StringWriter sw = new StringWriter(sb);
            sw.Write(c,0,4);
        }
細(xì)節(jié)37使用var創(chuàng)建隱型局部變量
var關(guān)鍵字指示編譯器能根據(jù)變量的初始化 表達(dá)式推斷出變量的類型。
細(xì)節(jié)38Lambda表達(dá)式
構(gòu)成:一個參數(shù)列表,Lambda操作符(=>),表達(dá)式()或語句塊{}
Lambda表達(dá)式有兩種。Lambda操作符右邊是表達(dá)式的叫做表達(dá)式Lambda,如果是一個大括號括起來的任意多條語句,那就是語句Lambda
Lambda表達(dá)式賦值給委托類型必須滿足一下條件:
1.Lambda表達(dá)式與委托類型的參數(shù)個數(shù)相同
2.Lambda表達(dá)式的每個參數(shù)都能被隱式的轉(zhuǎn)化為委托類型的參數(shù)類型
3.Lambda表達(dá)式的返回值能夠被隱式轉(zhuǎn)化為委托類型的返回值類型。
 delegate int AddOne(int i);
        delegate int ToAdd(int i,int j);
        delegate void Method();
        delegate int Method1();
        protected void Lambda()
        {
            AddOne addone;
            addone = x => x + 1; //隱式類型,表達(dá)式方式體
            addone = x => { return x + 1; };//隱式類型,語句方法體
            addone = (int x) => x + 1;//顯示類型,表達(dá)式方式體
            addone = (int x) => { return x + 1; };//顯示語句方法體類型,
            ToAdd myto = (x, y) => x + y;//多個參數(shù)
            Method method1 = () => { };//無參數(shù),表達(dá)式方式體
            Method1  method2 = () => 1;//無參數(shù),語句方法體

        }
細(xì)節(jié)39生成縮略圖的方法
Web應(yīng)用中傳輸較大圖片時除了采用壓縮格式傳輸外,還可以使用縮略圖的方式加快瀏覽速度。
生成圖片縮略圖主要應(yīng)用了Image類的GetThumbnailImage()方法
該方法返回當(dāng)前Image實例的縮略圖
public Image GetThumbnaiImage(
  int thumbWidth,//請求的縮略圖的寬度
  int thumbHeight,//請求的縮略圖的高度
  Image.GetThuumbnailImageAbort callback,//創(chuàng)建一個委托并在該參數(shù)中傳遞對此委托的引用。
  IntPtr callbackData//必須為Zero
)
 //生成縮略圖
        /// <summary>
        ///
        /// </summary>
        /// <param name="imgPath">原圖片路徑</param>
        /// <param name="thumbPath">縮略圖存儲路徑</param>
        /// <param name="width">原圖片的寬度</param>
        /// <param name="height">高度</param>
        private void Thumb(string imgPath, string thumbPath, double width, double height)
        {
            //生成縮略圖
            System.Drawing.Image image = System.Drawing.Image.FromFile(imgPath  );
            System.Drawing.Image.GetThumbnailImageAbort callb = null;
            int w, h;
            //根據(jù)實際的寬度和高度確定縮略圖的寬高
            if (width > height)
            {
                w = 100;
                h = Convert.ToInt32(Convert.ToSingle(height) / Convert.ToSingle(width)) * 80;

            }
            else
            {
                h = 100;
                w = Convert.ToInt32(Convert.ToSingle(width ) / Convert.ToSingle(height )) * 80;
            }
            System.Drawing.Image newimage = image.GetThumbnailImage(w,h,callb,new System .IntPtr ());
            //上傳縮略圖
            newimage.Save(thumbPath );
            newimage.Dispose();
            image.Dispose();

        }
細(xì)節(jié)40使用緩沖流
。net框架提供的在System.Io命令空間下的BufferedStream類可以實現(xiàn)緩沖數(shù)據(jù),減少對操作系統(tǒng)的調(diào)用次數(shù)。
BufferedStream類提供從基礎(chǔ)數(shù)據(jù)源或存儲庫讀取字節(jié)以及將字節(jié)寫入基礎(chǔ)數(shù)據(jù)源或存儲庫的實現(xiàn),在不需要緩沖區(qū)時可以防止緩沖區(qū)降低輸入和輸出速度。
BufferedStream類的Read()方法用于從當(dāng)前緩沖流復(fù)制到字節(jié)數(shù)組
public overrider int Read()
{
  byte[] array,//復(fù)制到的字節(jié)數(shù)組
  int offset,//表示從開始讀取的位置
  int count//要讀取的字節(jié)數(shù)
}
BufferedStream類的Write()方法將字節(jié)復(fù)制到緩沖流
public override int Write()
{
  byte[] array,//從字節(jié)數(shù)組中復(fù)制數(shù)據(jù)
  int offset,//表示從開始寫入的位置
  int count//寫入的字節(jié)數(shù)
}
    //將一個文件的內(nèi)容復(fù)制到另一個文件
        /// <summary>
        ///
        /// </summary>
        /// <param name="oPath">源文件路徑</param>
        /// <param name="copyPath">目標(biāo)文件路徑</param>
        private void Buf(string oPath, string copyPath)
        {
            Stream s1, s2;
            BufferedStream bs1, bs2;
            byte[]b=new byte[1024];
            int i;
            //分別以讀寫方式打開文件
            s1 = File.OpenRead(oPath );
            s2 = File.OpenWrite(copyPath );
            //使用緩沖流
            bs1 = new BufferedStream(s1 );
            bs2 = new BufferedStream(s2);
            i = bs1.Read(b,0,1024);
            //從文件1中讀取寫入到文件2中
            while (i > 0)
            {
                bs2.Write(b,0,i);
                i = bs1.Read(b,0,1024);
            }
            bs2.Flush ();
            s1 .Close ();
            bs2 .Close ();

        }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約