How to get the Index of a vector in C #?

2

I would like to know how I get the index of my current vector through c #, I already have a structure in code but there I get the value of that index and I do not want that, but I want to obtain its index to know if it is going to perform or not some action.

Here is my code

for (int x = 0; x < c;x++ )
            {
                vector[x]=c2;
                if (vector[x]==0) {
                }
                else if (vector[x] !=0)
                {

                    if (vector[x] > vector[x+1])
                    {
                        mayor3 = vector[x];

                    }

                }
            }
    
asked by David 26.09.2016 в 00:11
source

1 answer

1

There are some variables that I do not know where they come from, as in the case of c2 or mayor3 , but if you want to have the index you could simply assign it to a variable, such as

int indice = 0;

for (int x = 0; x < c;x++ )
{
    vector[x]=c2;
    if (vector[x] != 0)
    {
        if (vector[x] > vector[x+1])
        {
            mayor3 = vector[x];
            indice = x;
        }

    }
}

This way when you assign the result value you also do it from the vector index assigning the x

    
answered by 26.09.2016 / 00:47
source