微軟圖表控件示例代碼編譯報「應輸入 ;」「常量中有換行符」,實際是字符串字面量缺少右引號,導致編譯器將後續中文字符當作代碼解析。
this.label1.Text = "The Y data爒alue爄s bound to the chart using OleDb and燼n Access database, and爐h" + "e data is selected using a simple SQL query.?;
// 缺少結尾引號 ^ ^ 這裡的 ?; 被當作代碼
this.label9.Text = "This sample shows how to assign data to a chart series using a DataView object.?;
// 同樣缺少結尾引號
this.label1.Text = "The Y data爒alue爄s bound to the chart using OleDb and燼n Access database, and爐h" + "e data is selected using a simple SQL query.?;"; // 補上 "
this.label9.Text = "This sample shows how to assign data to a chart series using a DataView object.?;"; // 補上 "
文件 → 進階保存選項 → 編碼: Unicode (UTF-8 帶簽名) - 代碼頁 65001,統一團隊編碼。「兩個語句後面都少個引號。」—— 一語中的,問題極其簡單卻極具迷惑性。
遇到莫名其妙的語法錯誤,先檢查引號、括號、分號是否成對。