Hi guys,
I have this code - I am trying to find if a number is present in a given array using recursion. The thing is, I get the error "not all code paths return a value". I don't know how to fix this. Please advise.
using System;
namespace checkArrayForValue
{
class Program
{
static void Main(string[] args)
{
int target = 4;
int[] arr = { 1, 4, 2, 5, 6, 7 };
Console.WriteLine(FindTarget(target,arr,0));
}
public static bool FindTarget(int target, int[] arr, int index)
{
if (index >= arr.Length-1)
{
return false;
}
if (arr[index] == target)
{
return true;
}
FindTarget(target, arr, index + 1);
}
}
}