DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Quick Way To Compare Elements In Array Using FindAll() Method

01.30.2012
| 2383 views |
  • submit to reddit
        Following code shows an array. Further it also show you the best way to compare elements with a value. Following code will print total elements which are less than equal to 11.

   int[] array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14, 12, 13, 14 ,12,14,11,2,11,31};
     int[] array2 = Array.FindAll(array1,
                element => element <= 11);

            Response.Write("<br/>There are <b>" + array2.Length + "</b> element in array which are less than 11.");