Doubts with Arrays in C #

4

Good evening, everyone. I'm a beginner in programming and I have two questions:

  • When a double-array in C # exists, each array position starts as null or zero?

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

    li>
  • asked by anonymous 15.12.2015 / 23:34

    1 answer

    7
      

    When an array of type double in C # is reached, each position of the array starts without null or zero?

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

      

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

    Yes.

    array.Length
    

    I assume% with a array of any type.

      

    For example, I have an array of n positions and I want to insert another element in this array in an ordered sequence, except that such a position is unknown, that is, I need to know in some way 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 structures. It would be best to use array .

        
    15.12.2015 / 23:38