namespace error???

hi.
i create this code and unity give me this error :

error CS0116: A namespace can only contain types and namespace declarations

and this is my code :

using UnityEngine;
using System.Collections;
using UnityEditor;


public SquareState[] board = new SquareState[9];
public bool xTurn = true;



public class TicTakToeControl : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

please help me and edit my code . thanks of all.

You need to move the following code inside the public class TicTakControl brackets:

public SquareState[] board = new SquareState[9];
public bool xTurn = true;

So your code should look like this:

using UnityEngine;
using System.Collections;
using UnityEditor;
 
public class TicTakToeControl : MonoBehaviour {
  
    public SquareState[] board = new SquareState[9];
    public bool xTurn = true;

    // Use this for initialization
    void Start () {
 
    }
 
    // Update is called once per frame
    void Update () {
 
    }
}

Hi!

You can’t declare those variables outside your class, you can do this:

using UnityEngine;
using System.Collections;
using UnityEditor;
 

 
public class TicTakToeControl : MonoBehaviour {
 
    public SquareState[] board = new SquareState[9];
    public bool xTurn = true;

    // Use this for initialization
    void Start () {
 
    }
 
    // Update is called once per frame
    void Update () {
 
    }
}

Or if you need those variables to be used in other scripts , as it is said you have to use a namespace:

using UnityEngine;
using System.Collections;
using UnityEditor;


namespace Mynamespace{

    public SquareState[] board = new SquareState[9];
    public bool xTurn = true;

 public class TicTakToeControl : MonoBehaviour {



    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
 }


}

Then if you want to access those variables in another script just add:

using Mynamesapce;

to it.

regards.