C# program to check the length of courses is more than 2 characters using Linq

Here, we are going to learn how to check the length of courses is more than 2 characters using Linq in C#?
Submitted by Nidhi, on August 31, 2020

Here we will create an array of strings that contains courses. Then we check the length of all courses is more than two characters or not using Linq All() method.

Program:

The source code to check the length of courses is more than 2 characters using Linq, which is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to check the length of courses is 
//more than 2 characters using Linq

using System;
using System.Linq;

class LinqDemo
{
    static void Main(string[] args)
    {
        string [] courses = { "BCA", "MCA", "MBA", "CCNA"};

        bool isgreater = false;
        
        isgreater = courses.All(c=>c.Length>2);
        
        Console.WriteLine("The length of all courses is more than 2 characters? --> " + isgreater);
    }
}

Output:

The length of all courses is more than 2 characters? --> True
Press any key to continue . . .

Explanation:

In the above program, we created a LinqDemo that contains the Main() method. In the Main() method we created an array of strings that contain academic courses.

isgreater = courses.All(c=>c.Length>2);

The above code will return a boolean value, here we check the length of all courses which are more than 2 characters or not. If the length of all courses is more than 2 characters then All() method will return true otherwise it will return false.

C# LINQ Programs »


ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.