Ram Prasad

Ram Prasad

  • NA
  • 326
  • 18.2k

Not able to get rid of IndexOutOfRangeException

Apr 23 2019 9:46 PM
static void Main(string[] args)
{
int[] A = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
int[] B = { 4, 8, 8, 12, 15 };
int? prev = null;
{
for (int i = 0; i < B.Length; i++)
{
for (int j = 0; j < A.Length; j++)
{
if (B[i] < prev+1)
{
if (B[i] == A[j-1])
{
Console.WriteLine(B[i]);
i++;
}
if (B[i] == A[j])
{
Console.WriteLine(B[i]);
i++;
}
else
{
Console.WriteLine(0);
}
}
prev = B[i] ;
Console.WriteLine();
}
}
}
}

Answers (2)