Any Operator


The Any operator checks whether any element of a sequence satisfies a condition.


This sample determines whether any words in a string array contain the character sequence 'ei'. It uses Any, passing a lambda expression that uses the Contains method to perform the check.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication4

{

   class Program

   {

    static void Main(string[] args)

     {

      string[] words = { "believe", "relief", "receipt", "field" };


      bool iAfterE = words.Any(w => w.Contains("ei"));


        Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}",         iAfterE);




       Console.ReadLine();

      }

    }

}


 Output:


                    

Aspnet Related Tutorials

...more

New Aspnet Resources

...more

Copyright © 2013 VisualBuilder. All rights reserved