Doubts with Arrays in C#

Asked

Viewed 99 times

4

Good night, you guys. I am a beginner in programming and have two questions:

  1. When a double array is maintained in C#, each position of the array starts-without as null or zero?

  2. Is there a method that returns the last BUSY position of an array? For example, I have an array of n positions and I want to insert one more element in this array in an ordered sequence, only such a position is unknown, i.e., I need to know somehow the subsequent position that is empty.

1 answer

7

When a double array is maintained in C#, each position of the array starts-without as null or zero?

With zero. Here is a table with all the default values of C variables#.

Is there any method that returns the last OCCUPIED position of an array?

Yes.

array.Length

I suppose array one array of any kind.

For example, I have an array of n positions and I want to insert one more element in this array in an ordered sequence, only such a position is unknown, i.e., I need to know somehow the subsequent position that is empty.

To insert an element at the end of array, do so:

Array.Resize(ref array, array.Length + 1);
array[array.Length - 1] = valordouble;

arrays are not good dynamic structure. The best would be to use a List<double>.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.