概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
datatableを、検索してindexを求めよ。
サンプルコード
using System;
using System.Data;
using System.Linq;
namespace App
{
class Program {
static void Main(string[] args) {
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Age", typeof(int));
dt.Rows.Add(1, "太郎", 20);
dt.Rows.Add(2, "次郎", 15);
dt.Rows.Add(3, "三郎", 10);
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow row = dt.Rows[i];
if (Convert.ToInt32(row["id"]) == 2)
Console.WriteLine("index: {0}", i);
}
}
}
}
実行結果
index: 1
以上。