惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
有赞技术团队
有赞技术团队
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
博客园_首页
Y
Y Combinator Blog
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
雷峰网
雷峰网
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Help Net Security
P
Proofpoint News Feed
B
Blog
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - 挑战

从存储过程中读取相关信息 Blend Step by Step书籍笔记(第一章) WPF非轮询方式实时更新数据库变化SqlDependency 动态解析XAML文本构建WPF的UI 解决为'*********' 的游标已存在问题 数据表死锁查询和处理 SQL Server操作XML(六)XML FLOWR SQL Server操作XML(五)XML Query-XQuery SQL Server操作XML(四)XML数据类型 SQL Server操作XML(三)OPENXML函数功能 SQL Server操作XML(二)XML子句实例 SQL Server操作XML(一)XML子句 数据绑定 最为详尽的WPF类继承关系 WPF Diagram Designer Part 3:连接Item 照猫画虎WPF之二数据绑定 照猫画虎WPF之一:命名空间 解决WPF部署后客户端访问安全性问题 C#读取文本播放相应语音
LinQ数据访问
挑战 · 2012-05-28 · via 博客园 - 挑战

(1)利用Linq访问数组

  string[] s = new string[5]{"Leo","BackHam","David","Ronaldo","Roony"};
  var result = from s1 in s    //从数组S中选取
  where s1.Length > 3         //筛选条件是长度大于3
  orderby s1.ToString()        //根据内容排序
  select s1.ToString();         //展示内容

(2)利用Linq访问集合

    private List<Employee> GetEmploeeCollection()
        {
            List<Employee> e = new List<Employee>
           {
               new Employee(){ID="e1",Name="Tom",Age=23,Salary=34540},
               new Employee(){ID="e2",Name="Jim",Age=25,Salary=12230},
               new Employee(){ID="e3",Name="Bob",Age=33,Salary=87540},
               new Employee(){ID="e4",Name="Neo",Age=47,Salary=22112},
               new Employee(){ID="e5",Name="Leo",Age=54,Salary=52123},
               new Employee(){ID="e6",Name="David",Age=23,Salary=21222},
           };
           return e;
        }

    

       var result = from ep in GetEmploeeCollection()
                         where ep.Salary > 30000
                         orderby ep.Salary
                         select ep.Name;

(3)查询列的选取和格式化

var result = from ep in GetEmploeeCollection()
                         where ep.Salary > 30000
                         orderby ep.Salary
                         select new
                         {
                           name=ep.Name,               //显示员工名称
                           tax=ep.Salary*0.012        //显示个人所得税
                         };