Can't add script even though the file name and the class name are the same

I was trying to test the script in Game mode but Unity just stated “All Compile Errors must be fixed”. I removed the script from my Scene and I was able to enter the game mode. So the problem seems to be in the script.

I imported the same script back again and tried to attach it to Player sprite, but Unity now states: Can’t add component ‘Controls’ because it doesn’t exist. Please check if the file name and class name match.

So the filename is Controls.cs and here is the script:

using UnityEngine;
using System.Collections;

public class Controls : MonoBehaviour {

// Store the keys for players.
public KeyCode moveUp;
public KeyCode moveDown;

// The speed is the same for both of the players so we can assign it here.
public float playerSpeed = 10;

// Update is called once per frame
void Update () {
	if (Input.GetKey(moveUp)) {
		rigidbody2D.velocity.y = playerSpeed;
	} else if (Input.GetKey(moveDown)) {
		rigidbody2D.velocity.y = playerSpeed * -1;
	} else {
		rigidbody2D.velocity.y = 0;
	}
}

}

I program several languages fluently but I have little experience with C#.

Solved:

There were no syntax errors, but you can’t directly change the rigidbody2d.velocity.y with C#.

Instead you have to use vectors, for example: instead of this rigidbody2D.velocity.y = playerSpeed; use this rigidbody2D.velocity = new Vector2(0, playerSpeed);

After making these changes it worked perfectly fine.