How to find the index of the min value in a list

Hey guys,
I have a list of distances between an enemy unit and player units. I want to find the index of the min value so I can have my enemy go towards that unit. I have looked through google and there seems to be a C# function for min but it isnt working for me. Maybe the libraries are different? From what I read the code would look like this:

float minListIndex = distanceList.IndexOf(distanceList.Min());

But unity doesnt recognize the “.Min()”

You could try to sort the List first using Linq so the elements are arranged from lowest to highest, and then just get index 0.

Here’s related thread where I asked about Array sorting, this will get you started if you want to go that route. It’s actually pretty easy.

You can also iterate through all elements in the list like this:

float minDistance;

for(int i = 0; i < myList.Count - 1; i ++) {
     if(i == 0) {
          minDistance = myList*;*

}
if(myList < minDistance ) {
minDistance = myList*;*
}
}