Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C# Program to Check the Length of Courses is More than 2 Characters Using LINQ

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Given an array that contains a list of different courses like “DSA”, “OS”, “JavaScript”, etc., now our task is to check the length of all the courses present in the given array is more than 2 characters or not with the help of LINQ. So to do our task we use the All() method of LINQ. This method returns true if all the elements present in the given sequence satisfy the specified condition. Otherwise, it will return false.

Syntax:

array_name.All(iterator => iterator.Length > 2)

Where array_name is the input array and Length is the function used to check the length of each course.

Example:

Input  : { "cse", "it", "ft", "bio-tech", "chemical" }
Output : False

Input  : { "cse", "ece", "bio-tech", "chemical" }
Output : True

C#




// C# program to find the check the length of
// courses is more than 2 characters Using LINQ
using System;
using System.Linq;
  
class GFG{
  
static void Main(string[] args)
{
      
    // Create 5 courses
    string[] course1 = { "cse", "ece", "bio-tech", "chemical", "civil" };
    string[] course2 = { "DSA", "JS", "Kotlin", "C", "React" };
      
    // Checking the length of all courses 
    // is greater than 2 or not
    bool result1 = course1.All(display => display.Length > 2);
    bool result2 = course2.All(display => display.Length > 2);
      
    Console.WriteLine("Is the length of the courses " +
                      "is greater than 2 in course1?: " + result1);
                        
    Console.WriteLine("Is the length of the courses " +
                      "is greater than 2 in course2?: " + result2);
}
}

Output:

Is the length of the courses is greater than 2 in course1?: True
Is the length of the courses is greater than 2 in course2?: False
My Personal Notes arrow_drop_up
Last Updated : 28 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials