Use All to check if an array has string elements who have four letters in CSharp

Description

The following code shows how to use All to check if an array has string elements who have four letters.

Example


     /*  www. j  a  v  a  2  s . c  om*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


public class MainClass{

   public static void Main(string[] args){   

         String[] TestData = {"Zero", "One", "Two", "Three",
                              "Four", "Five", "Six", "Seven", 
                              "Eight", "Nine", "Ten"};

         var ThisQuery = TestData.All(ThisElement => ThisElement.Length == 4);

         Console.WriteLine("All elements have 4 characters: " + ThisQuery);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ