[問題] 新手不會debug

看板C_Sharp (C#)作者 (Jeff)時間12年前 (2013/02/18 13:02), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串1/1
小弟我剛學C#,有段程式看不出問題出在哪,是否有高手願意提點? 以下附上程式,也附上問題 1>C:\Users\99325113\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs(13,10,13,11): error CS1513: 必須是 } 1>C:\Users\99325113\Desktop\ConsoleApplication1\ConsoleApplication1\Program.cs(40,1,40,2): error CS1022: 必須是型別或命名空間定義,或檔案結尾 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { // /// <summary> // 將 Image 轉換為 Byte 陣列。 // </summary> // <param name="ImgPath">圖片路徑 。</param> public static byte[] ImageToBuffer(string ImgPath) { byte[] _ImageBytes; if (File.Exists(ImgPath)) { Image _Image = Image.FromFile(ImgPath); MemoryStream ms = new MemoryStream(); _Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); _ImageBytes = ms.GetBuffer(); ms.Dispose(); _Image.Dispose(); } else { _ImageBytes = null; } return _ImageBytes; } } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.64.84.134

02/18 13:45, , 1F
你把 ImageToBuffer這支 method寫到 Main裡面了 所以會錯
02/18 13:45, 1F

02/18 14:23, , 2F
所以必須在主程式呼叫?
02/18 14:23, 2F

02/18 17:58, , 3F
你把一個method寫到另外一個method裡,獨立出來,在main
02/18 17:58, 3F

02/18 17:58, , 4F
呼叫他
02/18 17:58, 4F
文章代碼(AID): #1H8RNcCO (C_Sharp)
文章代碼(AID): #1H8RNcCO (C_Sharp)