C# LINQ 쿼리식
MSDN : http://msdn.microsoft.com/ko-kr/library/bb397676.aspx
LINQ를 사용시 using 추가
using System.Linq;
<DataTable>에서의 LINQ
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add(1, "홍길동");
dt.Rows.Add(2, "이순신");
dt.Rows.Add(3, "세종대왕");
var qry = from q in dt.AsEnumerable()
where q.Field<string>("Name") == "홍길동"
select q;
foreach (var row in qry)
{
MessageBox.Show("ID : " + row["ID"] + " Name : " + row["Name"]);
}
<결과>
ID : 1 Name : 홍길동
<Control> 패널에 포함된 체크박스 LINQ
Control[] controls = new Control[this.groupPanel.Controls.Count];
this.groupPanel.Controls.CopyTo(controls, 0);
var control = from chk in controls
where chk is CheckBox
select chk;
foreach (var c in control)
{
if(((CheckBox)c).Checked == true)
MessageBox.Show("ControlName : " + c.Name);
}