C#のArray.TrueForAll()メソッド
C#のArray.TrueForAll()メソッドは、配列内のすべての要素が指定された述語で定義された条件に一致するかどうかを判断するために使用されます。
構文
以下は構文です-
public static bool TrueForAll<T> (T[] array, Predicate<T> match);
例
Array.TrueForAll()メソッドを実装する例を見てみましょう-
using System;
public class Demo{
public static void Main(){
Console.WriteLine("Array elements...");
string[] arr = { "bike", "bus"};
for (int i = 0; i < arr.Length; i++){
Console.Write("{0} ", arr[i]);
}
Console.WriteLine();
int lastIndex = Array.LastIndexOf(arr, "bus");
Console.WriteLine("Last Ocurrence of element bus is at index = "+lastIndex);
bool res = Array.TrueForAll(arr, ele => ele.StartsWith("b",
StringComparison.Ordinal));
if (res)
Console.Write("Every element in the array matches the conditions defined by the specified predicate.");
else
Console.Write("Eevery element in the array do not matche the conditions defined by the specified predicate");
}
} 出力
これにより、次の出力が生成されます-
Array elements... bike bus Last Ocurrence of element bus is at index = 1 Every element in the array matches the conditions defined by the specified predicate
-
JavaScript array.keys()メソッド
JavaScriptのarray.keys()は、配列のキーのみを持つ配列イテレータオブジェクトを作成します 以下は、array.keys()メソッドのコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <ti
-
JavaScript Array.from()メソッド
Array.from()は、指定された配列インスタンスから新しい配列オブジェクトを作成します。 以下は、配列from()関数のコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Docume