Error while trying to add numbers in an int32 array

Asked

Viewed 77 times

1

I am trying to store an array of ints to use periosteally, but came across a syntax error on the part . { 4, 7, 8, 9, 10 }

    private Int32[] m_FluxosPlataformas = null;
    public Int32[] FluxosPlataformas
    {
        get
        {
            if (m_FluxosPlataformas == null)
            {
                m_FluxosPlataformas =  { 4, 7, 8, 9, 10 } ; 
            }
            return m_FluxosPlataformas;
        }
    }
  • You tried to replace the line: m_FluxosPlataformas = { 4; 7, 8, 9, 10 } ; By: m_FluxosPlataformas = { 4, 7, 8, 9, 10 } ; ???

  • Yes, but still of error

1 answer

8


The array is a reference type and needs to be initialized.

Replace the code:

m_FluxosPlataformas =  { 4, 7, 8, 9, 10 } ; 

For:

m_FluxosPlataformas = new Int32[] { 4, 7, 8, 9, 10 };
  • 1

    Just to comment new Int32[] {...} can be exchanged for new [] {...}

Browser other questions tagged

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