How to initialize a class array in C#?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

    public class LandeData : MonoBehaviour {
    	public Land[] lande;
    
    
    	// Use this for initialization
    	void Start () 
    	{
    		lande[0] = new Land("Danmark", 100, 100, 100, 0, 5.5f, 35);
    		lande[1] = new Land("Amerika", 80, 80, 80, 0, 250, 50);
    	}
    
    	[System.Serializable]
    	public class Land
    	{
    		public string navn;
    		public int moral;
    		public int håb;
    		public int helbred;
    		public int indflydelse;
    		public float indbyggere;
    		public int forurening;
    
    		public int relationDanmark;
    		public int relationAmerika;
    		public int relationRusland;
    		public int relationIran;
    		public int relationKina;
    		public int relationSaudArab;
    		public int relationEngland;
    		public int relationIsrael;
    
    		public Land(string nav, int mor, int hå, int helb, int indf, float indb, int foruren)
    		{
    			navn = nav;
    			moral = mor;
    			håb = hå;
    			helbred = helb;
    			indflydelse = indf;
    			indbyggere = indb;
    			forurening = foruren;
    		}
    	}
    
    	// Update is called once per frame
    	void Update () 
    	{
    		gameObject.GetComponent<Text>().text = (lande[0].navn + "	" + lande[0].moral +"		"+ lande[0].håb +"		" + lande[0].indbyggere + "			" + lande[0].forurening + "

“);
GetComponent().text = (GetComponent().text + lande[1].navn + " " + lande[1].moral +” “+ lande[1].håb +” " + lande[1].indbyggere + " " + lande[1].forurening + "

");
}}

I am trying to make this work:

But it comes with the error:

IndexOutOfRangeException: Array index is out of range.

(wrapper stelemref) object:stelemref (object,intptr,object)

LandeData.Start () (at Assets/aMyStuff/Organiser Jorden/Scripts/LandeData.cs:12)

How do I make the array accessible?

you need to initialize the array before you can populate the indices of the array with instances of classes.

in your code above, lande is actually null, because you have not initialized the array yet.

you need to do that first, then assign each index. like so:

int numberOfLands = 2;

void Start ()
{
    
    lande = new Land[numberOfLands]; // create an array long enough for as many lands as you need to store

    lande[0] = new Land("Danmark", 100, 100, 100, 0, 5.5f, 35);
    lande[1] = new Land("Amerika", 80, 80, 80, 0, 250, 50);
}

Arrays in C# are somewhat objects, so you have to ask for the memory space for it before assigning to it

AnyType[] array = new AnyType[arraySize];

In your case:

void Start () 
{
    lande = new Land;
    //you'd need at least size = 2 for the following lines to work
    lande[0] = new Land("Danmark", 100, 100, 100, 0, 5.5f, 35);
    lande[1] = new Land("Amerika", 80, 80, 80, 0, 250, 50);
}

If instead what you want is to be able to access the array from the editor it wouldn’t make much sense to overwrite them on start, much less not checking it’s Length to make sure it can take the data.
Also if you want to use an array initialized by the editor on OnDrawGizmos or OnDrawGizmosSelected make sure to check that the array is not null and its length greater than 0.