diff --git a/archive/c/c-sharp/LinearSearch.cs b/archive/c/c-sharp/LinearSearch.cs new file mode 100644 index 000000000..0fbed3acb --- /dev/null +++ b/archive/c/c-sharp/LinearSearch.cs @@ -0,0 +1,38 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +public class LinearSearch +{ + public static bool Search(List list, int toFind) + { + foreach (int value in list) + { + if (value == toFind) + { + return true; + } + } + return false; + } + + public static void ErrorAndExit() + { + Console.WriteLine("Usage: please provide a list of integers (\"1, 4, 5, 11, 12\") and the integer to find (\"11\")"); + Environment.Exit(1); + } + + public static void Main(string[] args) + { + try + { + var list = args[0].Split(',').Select(i => Int32.Parse(i.Trim())).ToList(); + var toFind = Int32.Parse(args[1]); + Console.WriteLine(Search(list, toFind)); + } + catch + { + ErrorAndExit(); + } + } +}