当前位置:网站首页>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
边栏推荐
- OpenGL homework - Hello, triangle
- [开源] .Net ORM 访问 Firebird 数据库
- Dayu200 experience officer MPPT photovoltaic power generation project dayu200, hi3861, Huawei cloud iotda
- How does win11 unblock the keyboard? Method of unlocking keyboard in win11
- Leetcode SQL first day
- PKPM 2020软件安装包下载及安装教程
- Implementation method of data platform landing
- 三元表达式、各生成式、匿名函数
- EasyCVR配置中心录像计划页面调整分辨率时的显示优化
- Meta force force meta universe system development fossage model
猜你喜欢

The strongest installation of the twin tower model, Google is playing "antique" again?

反爬通杀神器

你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......

EasyCVR配置中心录像计划页面调整分辨率时的显示优化

Implementation method of data platform landing

Customer case | China law network, through observing the cloud, greatly shortens the time of fault location

Wechat official account oauth2.0 authorizes login and displays user information

Reinforcement learning - learning notes 9 | multi step TD target

NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?

How to choose the appropriate automated testing tools?
随机推荐
Win11如何解禁键盘?Win11解禁键盘的方法
Implementation method of data platform landing
Jerry's power on automatic pairing [chapter]
The difference between NPM uninstall and RM direct deletion
【JDBC Part 1】概述、获取连接、CRUD
operator
648. Word replacement
怎样写一个增广矩阵到txt文件中
How to realize the movement control of characters in horizontal game
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?
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
建立自己的网站(18)
[advanced MySQL] index details (I): index data page structure
OpenGL job coordinate system
Oracle advanced (VI) Oracle expdp/impdp details
Programming mode - table driven programming
NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
[开源] .Net ORM 访问 Firebird 数据库
Jerry's manual matching method [chapter]