当前位置:网站首页>LINQ query (2)
LINQ query (2)
2022-06-24 08:14:00 【flysh05】
1. Type filtering
object[] data = { "one", 2, 4, "Four", "five", 6 };
var query = data.OfType<string>();
foreach (var s in query)
{
Console.WriteLine(s);
}
Output : “one”, “Four”, “five”
2. Composite query
var ferrariDrivers = **from** r in Formula1.GetChampions()
**from** c in r.Cars
where c == "Ferrari"
orderby r.LastName
select r.FirstName + " " + r.LastName;
Compound query using method
var ferrariDrivers = Formula1.GetChampions()
**.SelectMany**(r => r.Cars, (r, c) => new {
Racer = r, Car = c })
.Where(r => r.Car == "Ferrari")
.OrderBy(r => r.Racer.LastName)
.Select(r => r.Racer.FirstName + " " + r.Racer.LastName);
3. grouping
var countries = from r in Formula1.GetChampions()
group r by r.Country into g
orderby g.Count() descending, g.Key
where g.Count() >= 2
select new
{
Country = g.Key,
count = g.Count()
};
Use method grouping
var countries = Formula1.GetChampions()
.GroupBy(r => r.Country)
.OrderByDescending**(g => g.Count())
.ThenBy(g => g.Key)
.Where(g => g.Count() >= 2)
.Select(g => new
{
Country = g.Key,
count = g.Count()
});
Grouping of nested objects
var countries = from r in Formula1.GetChampions()
group r by r.Country into g
let count = g.Count()
orderby count descending, g.Key
where count >= 2
select new
{
Country = g.Key,
Count = count,
Racers = from r1 in g
orderby r1.LastName
select r1.FirstName + " " + r1.LastName
};
边栏推荐
- Svn actual measurement common operation record operation
- Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
- The monthly salary of two years after graduation is 36K. It's not difficult to say
- Swift Extension NetworkUtil(網絡監聽)(源碼)
- Echart's experience (I): about y axis yaxis attribute
- Vulnhub target: boredhackerblog_ CLOUD AV
- Vulnhub靶机:BOREDHACKERBLOG_ CLOUD AV
- Shader common functions
- QOpenGL显示点云文件
- How to cancel the display of the return button at the uniapp uni app H5 end the autobackbutton does not take effect
猜你喜欢

Keep one decimal place and two decimal places

Swift Extension ChainLayout(UI的链式布局)(源码)

Swift Extension NetworkUtil(網絡監聽)(源碼)

Leetcode 207: course schedule (topological sorting determines whether the loop is formed)

5-if语句(选择结构)

模型效果优化,试一下多种交叉验证的方法(系统实操)

Swift extension networkutil (network monitoring) (source code)

单片机STM32F103RB,BLDC直流电机控制器设计,原理图、源码和电路方案

ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved

Solve the problem of notebook keyboard disabling failure
随机推荐
Chapter 4 line operation of canvas
Leetcode 515 find the leetcode path of the maximum [bfs binary tree] heroding in each row
1-4metaploitable2 introduction
51单片机_外部中断 与 定时/计数器中断
解决笔记本键盘禁用失败问题
Jenkins is too old try it? Cloud native ci/cd Tekton
How does dating software cut your leeks
搜索与推荐那些事儿
Swift 基礎 閉包/Block的使用(源碼)
Search and recommend those things
Transformers pretrainedtokenizer class
Simple summary of lighting usage
Atguigu---15- built in instruction
[run the script framework in Django and store the data in the database]
[teacher zhaoyuqiang] use the Oracle tracking file
Sql语句内运算问题
Swift 基础 闭包/Block的使用(源码)
[测试开发]初识软件测试
Solve the problem of notebook keyboard disabling failure
Open cooperation and win-win future | Fuxin Kunpeng joins Jinlan organization