C#: How to access static fields by name? Indexer?

Hello everyone. I’m an experienced Javascript writer, but I’m very new to C#, which is what my question is about.

I have a script in the “player” Game Object that looks like this:

using UnityEngine;
using System.Collections;

public class Controller : MonoBehaviour {
	
	static class directions
	{
		public static Vector2 left = new Vector2 (-1F, 0F);
		public static Vector2 right = new Vector2 (1F, 0F);
		public static Vector2 up = new Vector2 (0F, 1F);
		public static Vector2 down = new Vector2 (0F, -1F);
	}
	
	void Update()
	{
		if (isControllable ())
		{
			if (Input.GetKeyDown("left") || Input.GetKeyDown("a"))
			{
				slideCharacter("left");
			}
			else if (Input.GetKeyDown("right") || Input.GetKeyDown("d"))
			{
				slideCharacter("right");
			}
			else if (Input.GetKeyDown("up") || Input.GetKeyDown("w"))
			{
				slideCharacter("up");
			}
			else if (Input.GetKeyDown("down") || Input.GetKeyDown("s"))
			{
				slideCharacter("down");
			}
		}
	}

	bool isControllable ()
	{
		if (rigidbody2D.velocity.magnitude != 0) return false;
		return true;
	}

	void slideCharacter (string command)
	{
		Vector2 vect = directions[command];
		rigidbody2D.AddForce(vect, ForceMode2D.Impulse);
	}
	
}

The problem occurs in the slideCharacter method, when I try writing “directions[command]”.
I’m not able to access the values inside of the “directions” class this way. How can this be done?

Turn class “directions” into a Dictionary. Populate it with the keys “left, right, etc” and as values the vectors for each of those directions. Then you can simply check if the Dictionary contains the key you are looking for (command) and get the coresponding vector.

Something like:

Dictionary<string, Vector2> directions = new Dictionary<string, int>(){{"Left",new Vector2 (-1F, 0F)},{"Right", new Vector2 (1F, 0F)},{"Up", new Vector2 (0F, 1F)}, {"Down", new Vector2 (0F, -1F)}};

//now, to access our dictionary:

if (directions.ContainsKey(command))
            {
                 rigidbody2D.AddForce(directions[command], ForceMode2D.Impulse);
            }