char[] arr = { 'H', 'e', 'l', 'l', 'o' };
string s = new string(arr); // "Hello"
foreach (Control c in this.Controls)
{
if (c is DateTimePicker dtp)
{
// 處理 dtp
Console.WriteLine(dtp.Name);
}
}
注意:僅遍歷第一層,巢狀容器需遞迴。
bool HasFullWidth(string s) => s.Any(c => c > 255); // 簡易判斷:ASCII 範圍外視為全形
嚴謹做法應用 Char.GetUnicodeCategory 或 Microsoft.VisualBasic.Strings.StrConv。
DataSource 可接受實作 IList/IListSource 的任何物件(DataTable、List<T>、自訂集合)。直接操作儲存格:
// 寫入
dataGrid[row, col] = "aaaa";
// 讀取
string val = dataGrid[row, col]?.ToString();
本質上仍是操作底層 DataTable 的 Row/Column。
int undeleted = table.Rows.Count - table.DefaultView.Count;
// DefaultView 預設過濾掉 Deleted,故差值即為非刪除列數
設定 Form.Region 為 GraphicsPath 定義的形狀。參考:CodeProject 範例。
int dayOfWeek = (int)DateTime.Now.DayOfWeek; // 0=Sunday ... 6=Saturday
// 或
int dayOfWeek = DateTime.Now.DayOfWeek.GetHashCode();
int ascii = 'a'; // 97
// 或
int ascii = (int)s[0];
this.FormBorderStyle = FormBorderStyle.FixedSingle;
// 或 FixedDialog、Fixed3D、FixedToolWindow
DataGridView 取代,新專案請使用後者。