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);

        }
    }
}

Falling off the end of a function doesn't return anything meaningful. What you want is to return the result of the recursion (see line 13):

public static bool FindTarget(int target, int[] arr, int index)
{
    if (index >= arr.Length-1)
    {
        return false;
    }

    if (arr[index] == target)
    {
        return true;
    }

    return FindTarget(target, arr, index + 1);
}
 //look it this..
        public static bool ISExistsArrayValue(int[] array, int findValue)
        {
            if (array.Length > 0)
            {
                var result = array.Where(s => s == findValue).FirstOrDefault();
                if (result > 0)
                    return true;
            }
            return false;
        }
Comments
Totally irrelevant to the topic
This question has already been answered. Start a new discussion instead.