If they find the value, they return the number of tries.

If they don't find the value, they return -1 (just as String.IndexOf does).

Then call them both and save the results in separate variables, and it's easy to show your results.

In the methods it's easy to do as well: set a counter before the loop to 1, and increment it at the end of the loop. If you find the value, immediately return the counter.

If you reach the end of the method without finding the value, return -1:

C#

int LinearSearch(int[] data, int lookFor) { int tries = 1; foreach (int x in data) { if (x == lookFor) return tries; tries++; } return -1; }Use exactly the same pattern for BinarySearch and it is trivial to implement and easy to understand!