In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The editor will share with you how to use the LINQ Where clause. I hope you will get something after reading this article. Let's discuss it together.
The LINQ Where clause is actually implemented by extension.
The extension function corresponding to the LINQ Where clause implemented by Microsoft for us is actually defined as follows:
Namespace System.Linq {public delegate TResult Func (TArg0 arg0, TArg1 arg1); public static class Enumerable {public static IEnumerable Where (this IEnumerable source, Func predicate); public static IEnumerable Where (this IEnumerable source, Func predicate);}}
The definition of our extension function parameter: Func predicate looks at the green delegate code of the above code.
The parameter of the LINQ Where clause writes an Lambda expression
(dd, aa) = > dd.Length
< aa 就相当于 C# 2.0 的匿名函数。 LINQ中所有关键字比如 Select,SelectMany, Count, All 等等其实都是用扩展方法来实现的。上面的用法同样也适用于这些关键字子句。这个LINQ Where子句中Lambda 表达式第二个参数是数组索引,我们可以在Lambda 表达式内部使用数组索引。来做一些复杂的判断。具有数组索引的LINQ关键字除了Where还以下几个Select,SelectMany, Count, All。 Select子句使用数组索引的例子 下面代码有一个整数数组,我们找出这个数字是否跟他在这个数组的位置一样 public static void LinqDemo01() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var numsInPlace = numbers.Select((num, index) =>New {Num = num, InPlace = (num = = index)})
Console.WriteLine ("Number: In-place?")
Foreach (var n in numsInPlace)
Console.WriteLine ("{0}: {1}", n.Num, n.InPlace)
}
An example of using an array index in the SelectMany clause
An array of several sentences. We want to split these sentences into words and show each word in that sentence. The query statement is as follows:
Public static void Demo01 ()
{
String [] text = {"Albert was here"
"Burke slept late"
"Connor is happy"}
Var tt = text.SelectMany ((s, index) = > from ss in s.Split ('')
Select new {Word = ss, Index = index})
Foreach (var n in tt)
Console.WriteLine ("{0}: {1}", n.WordJournal n.Index)
}
After reading this article, I believe you have some understanding of "how to use LINQ Where clause". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for your reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.