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 Get Last Occurence Of An Elements In Array Using FindIndex Method

01.30.2012
| 3600 views |
  • submit to reddit
        // description of your code here

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 lastIndexOf14 = Array.FindLastIndex(array1,
   element => element == 14);

            Response.Write("<br/>Last Index of Element 14  is <b>" + lastIndexOf14 + "</b> in array.");