Question: The code is supposed to start at the biggest value (minValue) and compare each item in the array to it. If the item is smaller than minValue it is assigned to minValue and so on.

```
using System;

class Program {
    static void Main(string[] args) {
        int[] array=new []{76,78,98,34};
        int minValue=Int32.MaxValue;//maxvalue reassignes itself for each array[index] smaller than minvalue
        foreach(int index in array){
            if (array[index]<minValue)
               minValue=array[index];
        }

        Console.WriteLine(minValue);
    }
}

```

So why does it throw an unhandled exception? I don't get it.
Thanks in advance.

Answer: 
In your case index does not save the INDEX, but the VALUE. Therefore in the fist iteration, you have `index=76`, and you try to access `array[76]` but the array has only 4 elements, thus the exception.

So to find the min you can either do something like:

```
foreach(int element in array){
        if (element <minValue)
           minValue=element ;
    }

```

Or if you want to iterate via index:

```
for(int index=0; index<array.Length; index++){
        if (array[index]<minValue)
           minValue=array[index];
    }

```

Or make use of Linq instead `minValue = array.Min()`
```
using System;

class Program {
    static void Main(string[] args) {
        int[] array=new []{76,78,98,34};
        int minValue=Int32.MaxValue;//maxvalue reassignes itself for each array[index] smaller than minvalue
        foreach(int index in array){
            if (index<minValue)
               minValue=index;
        }

        Console.WriteLine(minValue);
    }
}

```