Advertisement
callumbinner22

Linear Search pt 1

Mar 9th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication57
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] footballers = { "Marco Reus", "Bastian Schwienstieger", "Wayne Rooney", "Paul Pogba", "Juan Mata", "Robert Lewandoski", "Cristiano Ronaldo" };
  14.  
  15.             string input;
  16.             Console.WriteLine("Searching for: ");
  17.  
  18.             Console.WriteLine(search(Console.ReadLine(),footballers));
  19.            
  20.  
  21.         }
  22.  
  23.         static int search(string input, string[] footballers)
  24.         {
  25.             int x =0;
  26.             foreach (string item in footballers)
  27.             {
  28.                 if (item == input)
  29.                 {
  30.                     return x;
  31.                    
  32.                 }
  33.                 x++;
  34.             }
  35.            
  36.             return -1;
  37.         }      
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement