当前位置:网站首页>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"));
边栏推荐
- 芯源&立创EDA训练营——无刷电机驱动
- 终于搞懂什么是动态规划的
- 【Note17】PECI(Platform Environment Control Interface)
- Leetcode weekly The 280 game of the week is still difficult for the special game of the week's beauty team ~ simple simulation + hash parity count + sorting simulation traversal
- 2:第一章:认识JVM规范1:JVM简介;
- 一文搞定class的微觀結構和指令
- Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
- openresty ngx_lua请求响应
- Multi sensor fusion of imu/ electronic compass / wheel encoder (Kalman filter)
- Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?
猜你喜欢
Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~
Vision Transformer (ViT)
Three.js-01 入门
Selenium+Pytest自动化测试框架实战
查看网页最后修改时间方法以及原理简介
Week 17 homework
CJ mccullem autograph: to dear Portland
第十七周作业
LeetCode145. Post order traversal of binary tree (three methods of recursion and iteration)
视频标准二三事
随机推荐
证明 poj 1014 模优化修剪,部分递归 有错误
Yiwen gets rid of the garbage collector
Simple and beautiful method of PPT color matching
Multi camera stereo calibration
基于脉冲神经网络的物体检测
[speech processing] speech signal denoising and denoising based on MATLAB low-pass filter [including Matlab source code 1709]
[digital signal denoising] improved wavelet modulus maxima digital signal denoising based on MATLAB [including Matlab source code 1710]
MoCo: Momentum Contrast for Unsupervised Visual Representation Learning
Marginal probability and conditional probability
Debian 10 installation configuration
一文搞定JVM的内存结构
Multi sensor fusion of imu/ optical mouse / wheel encoder (nonlinear Kalman filter)
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
(4)UART应用设计及仿真验证2 —— RX模块设计(无状态机)
并查集实践
npm ELECTRON_ Mirror is set as domestic source (npmmirror China mirror)
Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
Use of metadata in golang grpc
LeetCode——Add Binary
Detailed explanation of pointer and array written test of C language