Share Some Methods about Linq to Entry
Have a little busy recently, focus on the coding of PL/SQL,
Only share some methods for you.
/// <summary>
/// 获取系统进程
/// </summary>
private void SearchProcess()
{
var source = Process.GetProcesses().Select(process => new { process.Id, Name = process.ProcessName });
GridView1.DataSource = source;
GridView1.DataBind();
}
/// <summary>
/// 用来查询泛型
/// </summary>
private void SearchFromList()
{
List<string> list = new List<string> { "dog", "pig", "duck", "chicken" };
IEnumerable<string> result = list.Where(s => s.IndexOf("g") >= 0);
foreach (string re in result)
{
Response.Write(re);
Response.Write("<br/>");
}
}
/// <summary>
/// 用来查询对象数组
/// </summary>
private void SearchArray()
{
object[] Array = { 1, false, "ustb",1.1 };
var source = Array.Select(p => p.GetType().Name);
foreach (string output in source)
{
Response.Write(output);
Response.Write("<br/>");
}
}
/// <summary>
/// 用来查询字典
/// </summary>
private void SearchDictionary()
{
Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(0, "CHINA");
dic.Add(1, "USA");
dic.Add(2, "ENGLAND");
dic.Add(3, "SINGAPORE");
var source = from dicc in dic where dicc.Key % 2 == 0 select dicc.Value;
foreach (string da in source)
{
Response.Write(da);
Response.Write("<br/>");
}
}