While itsme86 provided you with a good answer to your real question , I suspect that you are better off redefining how you write this in full.
If this is your goal, I would recommend thinking about it differently. Instead of allocating an array of a fixed size and assigning certain values ββto it, you may need to use a List<int> :
List<int> intList = new List<int>(); intList.Add(34); intList.Add(65); intList.Add(98);
The number of elements will always be intList.Count , and you can add as many elements as you want without worrying about the "allocated size", as the list will automatically grow as needed. It will also not give you bad results if you add 0 to the list as an actual value, where counting non-zero elements will not be considered zero if it is a valid value.
Note that you can also access elements by index, as well as an array:
int secondValue = intList[1];
Reed copsey
source share