当前位置:网站首页>Remember an experience of using selectmany
Remember an experience of using selectmany
2022-07-07 22:18:00 【freelooppowter】
Recently, when transforming a function, in order to reduce the number of layers of circulation , So I thought I would List The list is mapped to a list that can directly use the particle size List list , Such a loop can solve the problem .
public class ConflictWordItemForDisplay
{
/// <summary>
/// Datum field
/// </summary>
public string BasisField { get; set; }
/// <summary>
/// keyword
/// </summary>
public string Keyword { get; set; }
/// <summary>
/// Conflicting words ( Support multiple words , Use... Between words , Separate )
/// </summary>
public string ConflictWord { get; set; }
/// <summary>
/// Discrimination field
/// </summary>
public List<string> JudgingFields { get; set; }
}The defined data class is similar to the above , It may be necessary to use a three-tier loop in actual use to make judgment , Similar to the following pseudo code
foreach (var item in conflictWordItemForDisplayList)
{
if ( The contents of the reference field .ToUpper().contains(item.Keyword.ToUpper()))
{
foreach (var judgingField in item.JudgingFields)
{
foreach (var word in item.ConflictWord.Split(','))
{
if (judgingField The content of the corresponding discrimination field .ToUpper().contains(word.ToUpper()))
{
// Conflict , Carry out corresponding treatment ( Prompt the user to let the user modify and so on )
}
}
}
}
}When the discrimination field types are few and fixed, the judgment logic can be used to reduce one layer of circulation .
If you use SelectMany How to minimize the granularity . Microsoft SelectMany The description of is to project each element of the sequence onto IEnumerable<T> And merge the result sequence into one sequence . Include the following overloads

Reduce the discrimination field to the minimum granularity :
var allConflictWordItemForDisplay = conflictWordItemForDisplayList.SelectMany(p => p.JudgingFields, (s, r) => new ConflictWordItemForDisplay() { BasisField=s.BasisField,Keyword=s.Keyword,ConflictWord=s.ConflictWord,JudgingFields=new List<string> { r} });Reduce conflicting words to the granularity of a single word :
allConflictWordItemForDisplay = allConflictWordItemForDisplay.SelectMany(p => p.ConflictWord.Split(','), (s, r) => new ConflictWordItemForDisplay() { BasisField = s.BasisField, Keyword = s.Keyword, ConflictWord = r, JudgingFields = s.JudgingFields });This is just SelectMany The way I use this question ,SelectMany There are other overloaded functions , When you use it, you can learn more about .
The following is Microsoft's official document , There are also use cases for easy understanding .
https://docs.microsoft.com/zh-cn/dotnet/api/system.linq.enumerable.selectmany?view=netframework-4.6.1
边栏推荐
- Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
- Node:504 error reporting
- Jerry's manual matching method [chapter]
- null == undefined
- DBSync新增对MongoDB、ES的支持
- Restapi version control strategy [eolink translation]
- How does win11 time display the day of the week? How does win11 display the day of the week today?
- The cyberspace office announced the measures for data exit security assessment, which will come into force on September 1
- [open source] Net ORM accessing Firebird database
- Wechat official account oauth2.0 authorizes login and displays user information
猜你喜欢

How does win11 time display the day of the week? How does win11 display the day of the week today?

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?

Px4 autonomous flight

Ad domain group policy management

PDF文档签名指南
![[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process](/img/80/11c2b539c217ecd6ba55668d3e71e9.png)
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process

OpenGL configuration vs2019

648. Word replacement

Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
![[JDBC Part 1] overview, get connection, CRUD](/img/53/d79f29f102c81c9b0b7b439c78603b.png)
[JDBC Part 1] overview, get connection, CRUD
随机推荐
Index summary (assault version)
L2:ZK-Rollup的现状,前景和痛点
Matplotlib drawing interface settings
Which futures company is the safest to open a futures account?
The whole network "chases" Zhong Xuegao
L'enregistreur de disque dur NVR est connecté à easycvr par le Protocole GB 28181. Quelle est la raison pour laquelle l'information sur le canal de l'appareil n'est pas affichée?
Time standard library
How to choose the appropriate automated testing tools?
npm uninstall和rm直接删除的区别
Pdf document signature Guide
How to make agile digital transformation strategy for manufacturing enterprises
【Azure微服务 Service Fabric 】在SF节点中开启Performance Monitor及设置抓取进程的方式
Reptile combat (VII): pictures of the king of reptiles' heroes
[open source] Net ORM accessing Firebird database
How to write an augmented matrix into TXT file
TCP/IP 协议栈
Leetcode SQL first day
Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
Jerry's configuration of TWS cross pairing [article]
Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?