C#:Tips
実行ファイルのパスを取得
Console.WriteLine(System.Windows.Forms.Application.ExecutablePath); //C:\My Application\Application.exe Console.WriteLine(System.Windows.Forms.Application.StartupPath); //C:\My Application
[dobon.net]自分のアプリケーションの実行ファイルのパスを取得する
VB6のApp.Pathと同じ事を行うには?
三項演算子
string s = (true) ? "True" : "False";
先頭、最後 ダブルコーテーション外し
string s = (true) ? "True" : "False"; Console.WriteLine(s); s = "\"Hello\"C#\"World\""; Console.WriteLine(s); s = s.Trim(new char[] { '"' }); Console.WriteLine(s); // (参考)全置換 s = s.Replace("\"", ""); Console.WriteLine(s);
データテーブル・データグリッドビュー
private void button1_Click(object sender, EventArgs e) { DataSet dataSet = new DataSet(); DataTable table = new DataTable("Table"); // カラム名の追加 table.Columns.Add("教科"); table.Columns.Add("点数", Type.GetType("System.Int32")); table.Columns.Add("氏名"); table.Columns.Add("クラス名"); // DataSetにDataTableを追加 dataSet.Tables.Add(table); //=========================================== // //=========================================== DataRow dr = table.NewRow(); dr["教科"] = "国語"; dr["点数"] = 90; dr["氏名"] = "田中 一郎"; dr["クラス名"] = "A"; dataSet.Tables["Table"].Rows.Add(dr); //=========================================== // //=========================================== table.Rows.Add("数学", 80, "田中 一郎", "A"); table.Rows.Add("英語", 70, "田中 一郎", "A"); table.Rows.Add("国語", 60, "鈴木 二郎", "A"); table.Rows.Add("数学", 50, "鈴木 二郎", "A"); table.Rows.Add("英語", 80, "鈴木 二郎", "A"); table.Rows.Add("国語", 70, "佐藤 三郎", "B"); table.Rows.Add("数学", 80, "佐藤 三郎", "B"); table.Rows.Add("英語", 90, "佐藤 三郎", "B"); //=========================================== // //=========================================== this.dgv.DataSource = table; }