harish reddy

harish reddy

  • NA
  • 162
  • 33.6k

Methods C Sharp

Feb 9 2018 8:30 PM
I am getting error " Not all code paths return a value" with this code? pls help.
 
static void Main(string[] args)
{
Console.WriteLine("Enter the lenth of Array");
int length = int.Parse(Console.ReadLine());
int[] array = new int[length];
for (int i = 0; i <= array.Length - 1; i++)
{
Console.WriteLine("Enter {0} element" ,i);
array[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("Enter the element");
int element = int.Parse(Console.ReadLine());
Positionoffirst(element, array);
Console.WriteLine(Positionoffirst(element,array));
}
static int Positionoffirst(int element, int[] array)
{
for (int i = 0; i <= array.Length-1; i++)
{
if (array[i]==element)
{
if (array[i]>array[i-1] && array[i]>array[i+1])
{
return 1;
}
}
else
{
return -1;
}
}
 

Answers (1)