Share Some Methods about Linq to Entry

ustbwuyi 2008-08-29 04:45:34
加精
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/>");
}
}
...全文
1423 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
sias_summer 2011-08-15
  • 打赏
  • 举报
回复
很明显第2种可读性低了那么一点
就这几行 合不合一起没任何实际的意义
pthiiu 2010-11-16
  • 打赏
  • 举报
回复

  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/>");
}



  List<string> list = new List<string> { "dog", "pig", "duck", "chicken" };
foreach (string re in list.Where(s => s.IndexOf("g") >= 0))
{
  Response.Write(re);
  Response.Write("<br/>");
}


第二种不是更好一些吗?
bl_song 2010-09-01
  • 打赏
  • 举报
回复
CSND不让收藏了
Adechen 2009-08-24
  • 打赏
  • 举报
回复
路过,收藏,谢谢
wohaoku 2008-09-10
  • 打赏
  • 举报
回复
还真是不错的啊!!!!!!
豪羊 2008-09-07
  • 打赏
  • 举报
回复
学习,前辈N人
wangping_li 2008-09-05
  • 打赏
  • 举报
回复
然后呢?这都是基本语法
solaker 2008-09-05
  • 打赏
  • 举报
回复
不错,支持
xingfuxiao 2008-09-04
  • 打赏
  • 举报
回复
linq不错
letisgoto 2008-09-04
  • 打赏
  • 举报
回复
Linq非常的强大,最近正学习中。。。。。。。。。
Martin-月影 2008-09-04
  • 打赏
  • 举报
回复
very good
liyunsheng613 2008-09-04
  • 打赏
  • 举报
回复
代码怎么很像C#呢?
hai_literature 2008-09-04
  • 打赏
  • 举报
回复
Linq非常的强大,我得好好学学
谢谢,支持你
berlin8600 2008-09-03
  • 打赏
  • 举报
回复
不知道现在有多少人在用LINQ??
teebye 2008-09-03
  • 打赏
  • 举报
回复
拿分
kimlr2008 2008-09-03
  • 打赏
  • 举报
回复
good good
aiwoming 2008-09-03
  • 打赏
  • 举报
回复
支持一下,牛
xingfuxiao 2008-09-03
  • 打赏
  • 举报
回复
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(" <
SlaughtChen 2008-09-03
  • 打赏
  • 举报
回复
顶一下
liuhuan0701 2008-09-03
  • 打赏
  • 举报
回复
纯学习。
加载更多回复(2)

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧