Since it is a simple array in which you have already reserved the memory, both functions will give you the initial size of the array. I recommend you use some auxiliary class like:
List<int> integers = new List<int>();
integers.Add(1);
integers.Add(4);
integers.Add(7);
int someElement = integers[1];
These classes allow you to know the size of the array with those functions. They also allow you not to have to reserve an X memory size, but it is reserved dynamically.
Edited:
In case the size should be given and knowing that a class work, I recommend that you create your own class "MiVector" which has as attributes a int[] vector
and a int contador
.
Example with pseudocode:
public class MiVector
{
// Class MiVector.
private int[] vector;
private int contador;
public int MiVector(int size)
{
vector = new int[size];
contador = 0;
}
//comportamiento de una cola (FIFO)
public void set(int value)
{
vector[contador]=value;
contador++;
}
public int get(int indice)
{
return vector[indice];
}
}
You could also use it as MiVector[5]
, for that you would have to overload the operator .
Another option (Completing what your colleagues have told you):
Work in this way:
int[] VectorImpar = new int[20];
int totalElementos = 0;
VertorImpar[0] = 22;
totalElementos++;
VertorImpar[1]++;
I hope this answers your question.