当前位置:网站首页>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
};
边栏推荐
- C# Lambda
- transformers PreTrainedTokenizer类
- 3-列表简介
- "Adobe international certification" about Adobe Photoshop, creating and modifying brush tutorials?
- How to design a highly available and extended image storage function
- FPGA的虚拟时钟如何使用?
- 5-if语句(选择结构)
- 1-4metasploitable2介绍
- 不止于观测|阿里云可观测套件正式发布
- Moonwell Artemis is now online moonbeam network
猜你喜欢

Ad-gcl:advantageous graph augmentation to improve graph contractual learning

Search and recommend those things

Simple summary of lighting usage

没有专业背景,还有机会成为机器学习工程师吗?

More than observation | Alibaba cloud observable suite officially released

Vulnhub靶机:BOREDHACKERBLOG: SOCIAL NETWORK

Utilisation de la fermeture / bloc de base SWIFT (source)

Keep one decimal place and two decimal places

研究生英语期末考试复习

有关iframe锚点,锚点出现上下偏移,锚点出现页面显示问题.iframe的srcdoc问题
随机推荐
QOpenGL显示点云文件
C# Lambda
5-if语句(选择结构)
Analysis of abnormal problems in domain name resolution in kubernetes
Swift 基础 闭包/Block的使用(源码)
Search and recommend those things
redolog和binlog
模型效果优化,试一下多种交叉验证的方法(系统实操)
Leetcode 207: course schedule (topological sorting determines whether the loop is formed)
Application of JDBC in performance test
On the H5 page, the Apple phone blocks the content when using fixed to locate the bottom of the tabbar
Introduction of model compression tool based on distiller
How does dating software cut your leeks
June 27, 2021: given a positive array arr, it represents the weight of several people
"Adobe international certification" about Adobe Photoshop, creating and modifying brush tutorials?
Phonics
自动化测试的未来趋势
Moonwell Artemis is now online moonbeam network
Shader common functions
Swift Extension NetworkUtil(网络监听)(源码)