当前位置:网站首页>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"));
边栏推荐
- C Primer Plus Chapter 9 question 9 POW function
- 判斷二叉樹是否為完全二叉樹
- VS2010 writes DLL and unit test of dynamic link library, and transfers the correctness of DLL test
- Element operation and element waiting in Web Automation
- It is proved that POJ 1014 module is optimized and pruned, and some recursion is wrong
- asp. Net pop-up layer instance
- [screen recording] how to record in the OBS area
- UVA11294-Wedding(2-SAT)
- 透彻理解JVM类加载子系统
- 使用rewrite规则实现将所有到a域名的访问rewrite到b域名
猜你喜欢
Matlab smooth curve connection scatter diagram
There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!
Go语言实现原理——锁实现原理
Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
一文搞定JVM的内存结构
Use of grpc interceptor
Finally understand what dynamic planning is
PLC编程基础之数据类型、变量声明、全局变量和I/O映射(CODESYS篇 )
3: Chapter 1: understanding JVM specification 2: JVM specification, introduction;
一文搞定class的微觀結構和指令
随机推荐
Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
UVA11294-Wedding(2-SAT)
2022 registration examination for safety management personnel of hazardous chemical business units and simulated reexamination examination for safety management personnel of hazardous chemical busines
Object detection based on impulse neural network
3: Chapter 1: understanding JVM specification 2: JVM specification, introduction;
The method and principle of viewing the last modification time of the web page
判断二叉树是否为完全二叉树
February 13, 2022-4-symmetric binary tree
Dynamic memory management (malloc/calloc/realloc)
Sum of two numbers, sum of three numbers (sort + double pointer)
[speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]
Nacos installation and service registration
Finally understand what dynamic planning is
Creative mode 1 - single case mode
Matlab smooth curve connection scatter diagram
UVA – 11637 Garbage Remembering Exam (组合+可能性)
grafana工具界面显示报错influxDB Error
Krypton Factor-紫书第七章暴力求解
Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
Use of grpc interceptor