Some of this depends on what you want to do with the string once you have it. You can use the code in @PepitoFernandez's answer to convert it to an enum. If you'd like to then use it to determine what method to call against an object, you have a few options.
The first is that if it's a known set of strings, you could use a switch
statement:
switch (stringVariable) {
case "stringA": methodA(); break;
case "stringB": methodB(); break;
...
// If you get a "bad" string, you WANT to throw an exception to make
// debugging easier
default: throw new ArgumentException("Method name not recognized");
}
Obviously, you can also replace this with enum values if you do the conversion first. (That's actually not a bad idea because if you get a "bad" string you
The other option (if you want to do it dynamically at runtime) is to do the call using reflection, like this:
public class SomeClass
{
public void MethodA()
{
Console.WriteLine("MethodA");
}
}
static void Main(string[] args)
{
Type type = typeof(SomeClass);
// Obviously, you'll want to replace the hardcode with your string
MethodInfo method = type.GetMethod("MethodA");
SomeClass cls = new SomeClass();
// The second argument is the parameters; I pass null here because
// there aren't any in this case
method.Invoke(cls, null);
}