this is the problem [enter image description here][1]
class Program
 {
 /\* I 'am sorry, but if written this code in french so I will explain the name of variables in English, and what are they doing

```
     and Yes I am aware this code is spaghetti and I would appreciate if there is a better way to write it 

      T is an Array, and cible is a target */

public static int []  getRange(int[] T, int cible)

    {
        // T_indices is an Array of indexes 
        int[] T_indices = new int[10]; 

        //cpt is a counting variable
        int cpt=0;
        for (int i = 0; i < T.Length; i++)
        {
            if(T[i]==cible)
            {
                for (int j = i; j < T.Length; j++)
                {
                    if(T[i]==T[j])
                    {

                        T_indices[cpt] = j;
                        cpt++;
                    }
                    else
                    {
                        break;
                    }
                }
                break;
            }
        }

```

//checking if the element doesn't existe so we can return a -1

```
        if(cpt==0)
        {
            T_indices = new int[1];
            T_indices[0] = -1;
            return T_indices;
        }

        else
        {
            //T_indices_Finaux is the final index Array

            int[] T_indices_Finaux = new int[2];
            T_indices_Finaux[0] = T_indices[0];
            // Max doesn't need explanation I guess
            int max = T_indices[0];
            for (int i = 0; i < T_indices.Length; i++)
            {
                if(max< T_indices[i])
                {
                    max = T_indices[i];
                }

            }
            T_indices_Finaux[1] = max;

                if(T_indices_Finaux[0]== T_indices_Finaux[1])
            {
                T_indices_Finaux = new int[1];
                T_indices_Finaux[0] = T_indices[0];

            }

            return T_indices_Finaux;

        }
    }

```

// here we put this spaghetti code to the test suprisenly wroking out

```
    static void Main(string[] args)
    {

        int[] T = { 1, 2, 2, 2, 2, 3, 4, 7, 8, 8 };

        for (int i = 0; i < getRange(T, 2).Length; i++)
        {

                Console.WriteLine(getRange(T, 2)[i]);

        }
        Console.Read();
    }
}

```