官术网_书友最值得收藏!

Determining the values in a collection

Now that we have collections of items to go through, we can do that. To do this, enter the following:

IEnumerable<int> valuesMoreThanTen = lst.Where(x => x >10);

Here, we first operate on the list of numerical values, so we say valuesMoreThanTen. To make this happen, you enter the name of the list, which is lst. Notice in the pop-up tip all of the functions that have become available. One of them is Where<>. After you select Where<>, you can specify a condition that applies, in our case, where x is such that x is greater than 10, or (x => x > 10), and close this with a semicolon.

If you hover your mouse over Where, and look where it says IEnumerable<int>, it says that it returns, in other words, an IEnumerable construct, which we can iterate through with a foreach loop, for example. Further, it says (Func<int,bool>... and then there is a predicate delegate. So, we will take each value and we'll basically apply some action to it. We'll check whether some condition holds: either the condition holds on it or it doesn't.

As you can see, we basically have LINQ, and then we have inside that, a Lambda expression. So, to make use of it, you'll enter the following next:

valuesMoreThanTen.ToList().ForEach(x => sampLabel.Text += $"<br>x={x}");
主站蜘蛛池模板: 湾仔区| 四会市| 武宣县| 武胜县| 连州市| 清丰县| 太保市| 达日县| 万州区| 磐石市| 民县| 深水埗区| 三河市| 饶平县| 定安县| 喀什市| 平乡县| 麦盖提县| 民权县| 子洲县| 噶尔县| 景泰县| 温宿县| 丹棱县| 习水县| 民权县| 木兰县| 澎湖县| 瑞昌市| 北宁市| 紫云| 新乡县| 沈阳市| 论坛| 金湖县| 万全县| 白水县| 建阳市| 灵丘县| 安达市| 南宁市|