Algorithms: Searching Linear Search in C# Scan the input from left to right until the target is found. csharp static int linear_search(ReadOnlySpan<int> a, int target) { checked { int n = a.Length; alg_require(((n >= 0) && (n <= 1000000))); alg_require((a.Length == n)); int i = 0; while ((i < n)) { if ((a[i] == target)) { return i; } i = (i + 1); } Nov 15, 2026 csharp