發表文章

目前顯示的是 8月, 2023的文章

[C#] 取得Guid

取得Guid   using System; Console.WriteLine(Guid.NewGuid()); 參考網址:  https://learn.microsoft.com/zh-tw/dotnet/api/system.guid.newguid?view=net-7.0 https://blog.csdn.net/WuLex/article/details/109571681 By Hao★

[C#] Stream.CopyTo 方法使用

  Stream.CopyTo 方法使用   //創建新的stream MemoryStream destination = new MemoryStream(); using (FileStream source = new FileStream("C:\temp\Machine.jpg", FileMode.Open)) { //將來源source,複製到目的地destination. source.CopyTo(destination); } 參考網址:  https://learn.microsoft.com/zh-tw/dotnet/api/system.io.stream.copyto?view=net-7.0 錯誤案例: //創建新的stream MemoryStream destination = new MemoryStream(); //來源端stream FileStream source = new FileStream("C:\temp\Machine.jpg", FileMode.Open, FileAccess.Read); destination.CopyTo(source); //錯誤訊息System.NotSupportedException: 'Stream does not support writing.' //原因:因為source是唯讀的,且來源端與目的地位置應交換 參考網址:  https://learn.microsoft.com/zh-tw/dotnet/api/system.notsupportedexception?view=net-7.0 By Hao★