当前位置:网站首页>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
};
边栏推荐
- [测试开发]初识软件测试
- 51 single chip microcomputer_ External interrupt and timer / Counter interrupt
- 1-4metasploitable2介绍
- 3-list introduction
- How to cancel the display of the return button at the uniapp uni app H5 end the autobackbutton does not take effect
- These dependencies were not found: * core JS / modules / es6 array. Fill in XXX
- Cold thinking on the hot track: multiplier effect is the fundamental requirement of East West calculation
- SVN实测常用操作-记录操作大全
- Chapter 3: drawing triangles
- JDBC 在性能测试中的应用
猜你喜欢

OC Extension 检测手机是否安装某个App(源码)
![[run the script framework in Django and store the data in the database]](/img/6b/052679e5468e5a90be5c4339183f43.png)
[run the script framework in Django and store the data in the database]

More than observation | Alibaba cloud observable suite officially released

The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain

Pagoda panel installation php7.2 installation phalcon3.3.2

On the H5 page, the Apple phone blocks the content when using fixed to locate the bottom of the tabbar

Examples of corpus data processing cases (reading multiple text files, reading multiple files specified under a folder, decoding errors, reading multiple subfolder text, batch renaming of multiple fil

解决笔记本键盘禁用失败问题

不止于观测|阿里云可观测套件正式发布

Vulnhub靶机:BOREDHACKERBLOG_ CLOUD AV
随机推荐
Solution to the error of running NPM run eject
Simple summary of lighting usage
Phonics
Selenium IDE的安装以及使用
Application of JDBC in performance test
From jsonpath and XPath to spl
[ACNOI2022]做过也不会
Open cooperation and win-win future | Fuxin Kunpeng joins Jinlan organization
快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
Sql语句内运算问题
[run the script framework in Django and store the data in the database]
Leetcode exercise - jumping game, combination summation
June 27, 2021: given a positive array arr, it represents the weight of several people
Qopengl display point cloud file
[nilm] non intrusive load decomposition module nilmtk installation tutorial
宝塔面板安装php7.2安装phalcon3.3.2
Swift extension networkutil (network monitoring) (source code)
AWTK 最新动态:Grid 控件新用法
Search and recommend those things
Easyplayerpro win configuration full screen mode can not be full screen why