当前位置:网站首页>C# Linq Demo
C# Linq Demo
2022-07-05 23:18:00 【ou. cs】
select
Assign values to new types
List<Students> studentsSource = new List<Students>()
{
new Students()
{
Id= 1,
Name="11",
ClassId=1,
Age=25,
},
new Students()
{
Id= 2,
Name="22",
ClassId=2,
Age=22,
},
new Students()
{
Id= 3,
Name="33",
ClassId=1,
Age=33,
},
new Students()
{
Id= 4,
Name="44",
ClassId=2,
Age=21,
},
new Students()
{
Id= 5,
Name="55",
ClassId=5,
Age=55,
},
};
var query =studentsSource.Select(x => new {
id=x.Id,age=x.Age>50?999:0});
foreach (var item in query)
{
Console.WriteLine(item.id);
Console.WriteLine(item.age);
Console.WriteLine("\n");
}
join
List<StuClass> stuClasses = new List<StuClass>()
{
new StuClass{
Id=1,ClassName="11"},
new StuClass{
Id=2,ClassName="22"},
new StuClass{
Id=3,ClassName="33"},
new StuClass{
Id=4,ClassName="44"},
};
// == Change it into equals
{
var query2 = from s in studentsSource
join c in stuClasses on s.ClassId equals c.Id
select new StuAndClass {
Id=s.Id,
ClassId=s.ClassId,
Age=s.Age,
ClassName=c.ClassName,
};
var query3 = studentsSource.Join(stuClasses, s => s.ClassId, c => c.Id, (s, c) => new StuAndClass
{
Id = s.Id,
ClassId = s.ClassId,
Age = s.Age,
ClassName = c.ClassName,
});
}
other
// Get the first data
//var query3 = studentsSource.Take(2);
//var query4 = studentsSource.Skip(2);
//var query5 = studentsSource.OrderBy(s=>s.Name);
var query2 = studentsSource.Select(s => s.Name);
var query6 = studentsSource.Where(s=>s.Name.Contains("1"));
边栏推荐
- 【Note17】PECI(Platform Environment Control Interface)
- 并查集实践
- 秒杀系统的设计与实现思路
- openresty ngx_lua请求响应
- JVM的简介
- 2022 registration examination for safety management personnel of hazardous chemical business units and simulated reexamination examination for safety management personnel of hazardous chemical busines
- VS2010 writes DLL and unit test of dynamic link library, and transfers the correctness of DLL test
- fibonacci search
- Three.js-01 入门
- asp.net弹出层实例
猜你喜欢
![[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]](/img/df/9aa83ac5bd9f614942310a040a6dff.jpg)
[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]

3: Chapter 1: understanding JVM specification 2: JVM specification, introduction;

2022 R2 mobile pressure vessel filling review simulation examination and R2 mobile pressure vessel filling examination questions

2:第一章:认识JVM规范1:JVM简介;
![[untitled]](/img/8c/607776e79d66acf9282dca127e12e1.jpg)
[untitled]

Non rigid / flexible point cloud ICP registration

The method and principle of viewing the last modification time of the web page

利用LNMP实现wordpress站点搭建

Go语言实现原理——锁实现原理

Dynamic memory management (malloc/calloc/realloc)
随机推荐
芯源&立创EDA训练营——无刷电机驱动
媒体查询:引入资源
[untitled]
14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!
Initial experience | purchase and activate typora software
透彻理解JVM类加载子系统
Finally understand what dynamic planning is
Three. Js-01 getting started
利用LNMP实现wordpress站点搭建
[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
证明 poj 1014 模优化修剪,部分递归 有错误
openresty ngx_lua正则表达式
It is proved that POJ 1014 module is optimized and pruned, and some recursion is wrong
【Note17】PECI(Platform Environment Control Interface)
Use the rewrite rule to rewrite all accesses to the a domain name to the B domain name
(4) UART application design and simulation verification 2 - TX module design (stateless machine)
2022 G3 boiler water treatment simulation examination and G3 boiler water treatment simulation examination question bank
npm ELECTRON_ Mirror is set as domestic source (npmmirror China mirror)
Realize reverse proxy client IP transparent transmission
What is the process of building a website