C#
 Computer >> コンピューター >  >> プログラミング >> C#

C#LinqZipメソッド


述語とZipメソッドを使用してシーケンスをマージします。

マージするアレイは次のとおりです。

int[] intArray = { 10, 20, 30, 40 };
string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };

次に、Zipメソッドを使用して両方のアレイをマージしましょう。

intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two)

以下は私たちのコードです。

using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
   public static void Main() {
      int[] intArray = { 10, 20, 30, 40 };
      string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };
      var mergedSeq = intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two);
      foreach (var ele in mergedSeq)
      Console.WriteLine(ele);
   }
}

出力

10 Jack
20 Tim
30 Henry
40 Tom

  1. C#LinqWhereメソッド

    Whereメソッドは、述語に基づいて値の配列をフィルタリングします。 ここで、述語は70を超える要素をチェックしています。 Where((n, index) => n >= 70); 例 using System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] arr = { 10, 30, 20, 15, 90, 85, 40, 75 }; &n

  2. C#Linq Distinct()メソッド

    個別の要素を取得するには、Distinct()メソッドを使用します。 以下は、重複する要素を含むリストです。 List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 }; 次に、個別の要素を取得します- points.AsQueryable().Distinct(); 例全体を見てみましょう- 例 using System; using System.Linq; using System.Collections.Generic; class Demo {   &nbs