// 字串轉整數
int val = Int32.Parse(str); // 或 int.TryParse(str, out val)
// DateTime 格式化字串
string dateStr = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
var list = new ArrayList();
list.Add(new DictionaryEntry(1, "進入"));
list.Add(new DictionaryEntry(2, "離開"));
comboBox1.DataSource = list;
comboBox1.DisplayMember = "Value"; // 顯示文字
comboBox1.ValueMember = "Key"; // 實際值
// 取得選取值
string selected = comboBox1.SelectedValue?.ToString() + "," + comboBox1.Text;
string ckvalue = "";
// 反向迴圈避免刪除時索引錯亂
for (int i = listView2.Items.Count - 1; i >= 0; i--)
{
if (listView2.Items[i].Checked)
{
ckvalue += listView2.Items[i].SubItems[3].Text + ",";
listView2.Items.RemoveAt(i);
}
}
var rys = new List();
RyBean[] rysArr = rys.ToArray();
| 項目 | 注意事項 |
|---|---|
| .NET 版本 | WinCE 通常使用 .NET Compact Framework 3.5,API 子集有限 |
| 反射/泛型 | 受限,避免複雜反射、動態程式碼生成 |
| 記憶體 | 嵌入式裝置記憶體小,注意物件釋放、避免大型集合長駐 |
| 檔案系統 | 路徑區分大小寫視儲存裝置而定,建議統一使用 Path.Combine |
| UI 執行緒 | 同樣需 Invoke/BeginInvoke 跨執行緒更新 UI |
| 資料庫 | 常用 SQL Server Compact (SQLCE),ADO.NET API 類似但功能精簡 |
| 部署 | CAB 檔安裝,需包含 CF 框架執行環境 |
using System;
using System.Collections; // ArrayList, DictionaryEntry
using System.Collections.Generic; // List
using System.Windows.Forms; // ComboBox, ListView
using System.Data.SqlServerCe; // SQL CE
WinCE/.NET CF 開發雖然環境受限,但掌握核心 API 差異與資源管理技巧,仍能開發穩定可靠的嵌入式應用。