Trouble with an array of classes - Cannot implicitly convert type

Hi everyone, I have created a script that I use to create and add to an array of objects.
The code for the class constructor is as follows;

using UnityEngine;
using System.Collections;

public class Dialogue: MonoBehaviour{
	
	private int _x;
	private int _y;
	private string _text = "";
	
	public int X {
		get { return _x; }
		set { _x = value; }
	}
	
	public int Y {
		get { return _y; }
		set { _y = value; }
	}
	
	public string Text {
		get { return _text; }
		set { _text = value; }
	}
}

extending this, I have created a function in a separate file which enabled me to create new objects and add them to the array;

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ArrayTest: MonoBehaviour {
	
	List<Dialogue> boxList = new ArrayList();
	
	public void DialogueAdd(string text, int width, int height){
		
		Dialogue newDiag = new Dialogue();
		newDiag.Dialogue = text;
		newDiag.X = width;
		newDiag.Y = height;
		
		boxList.Add (newDiag);
	}
	
	void Start(){
		DialogueAdd ("some text", 22, 42);
		DialogueAdd ("some more text", 12, 24);
		DialogueAdd ("even more text", 6, 22);
		Debug.Log (boxList);
	}
}

The problem is, when my script is compiled I get the following error;

Assets/Scripts/Dialogue/ArrayTest.cs(7,49): error CS0029: Cannot implicitly convert type `System.Collections.ArrayList' to `System.Collections.Generic.List<Dialogue>'

You can not use the ‘new’ keyword to initialize MonoBehaviour classes.

Edit:
To sum up:

  1. Place Dialog class before ArrayTest.
  2. Remove the inheritance from MonoBehaviour of Dialog.
  3. Change line to: List < Dialog > boxList = new List < Dialog >();

(Remove the unneeded spaces…they are there since otherwise the ‘<’ and ‘>’ are regarded as HTML tags.

You defined a List but you did a new ArrayList:

List< X >boxList = new ArrayList();

So:

List< X >boxList = new List< X >();

Also, your Dialogue class doesn’t have to extend MonoBehavior.

that should read

List<Dialogue> boxList = new List<Dialogue>();

its escaping the after each list

  1. Dialogue is MonoBehaviour class

  2. you can’t use constructor for it dircetly so remove MonoBehaviour from first class

  3. you need to create constructor overload for the class Dialouge

    public class Dialogue {

    private int _x;
    
    private int _y;
    
    private string _text = "";
    
    public int X {
    	get { return _x; }
    	set { _x = value; }
    }
    
    public int Y {
    	get { return _y; }
    	set { _y = value; }
    }
    
    public string Text {
    	get { return _text; }
    	set { _text = value; }
    }
    
    public Dialogue (string s, int x, int y) {
    	_text = s; 
    	_x = x;
    	_y = y;
    }
    

    }

now you can use it in List or arrayList