Search , insert and delete in an unsorted array | C # program to implement linear search in unsorted arrays ; Function to implement search operation ; Driver Code ; Using a last element as search element
using System ; class main { static int findElement ( int [ ] arr , int n , int key ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == key ) return i ; return - 1 ; } public static void Main ( ) { int [ ] arr = { 12 , 34 , 10 , 6 , 40 } ; int n = arr . Length ; int key = 40 ; int position = findElement ( arr , n , key ) ; if ( position == - 1 ) Console . WriteLine ( " Element ▁ not ▁ found " ) ; else Console . WriteLine ( " Element ▁ Found ▁ at ▁ Position : ▁ " + ( position + 1 ) ) ; } }