It is not possible to check parameters compile time because the compiler don't know what is coming in following case:
string value = Console.In.Readline();
SomeMethod(value); // How does compile know what is given to SomeMethod
Besides that, if behavior depends on string variables I would consider to refactor or to use proper error handling.
3 ways to refactor:
1: Use enums: Compile time errors
public enum MyInputEnum { Input1, Input2 }
public void SomeMethod(MyInputInum value) { .. }
SomeMethod(MyInputEnum.Input2); // Compiles
SomeMethod(MyInputEnum.Input3); // Compile Error because Input3 not defined
2: Use interfaces: Compile time errors
public interface IInputDescription { }
public class InputClass1 : IInputDescription { .. }
public class InputClass2 : IInputDescription { .. }
public class ErrorClass { .. } // This example class does not implement IInputDescription
public void SomeMethod(IInputDescription value) { .. }
SomeMethod(new InputClass2()); // Compiles
SomeMethod(new ErrorClass()); // Compile error
3: Use Error handling: Runtime errors
// Option 1
public void SomeMethod(string value)
{
if(!value.Equals("StringA") && !value.Equals("StringB"))
throw new ArgumentException("Invalid argument");
...
}
// Option 2
public void SomeMethod(string value)
{
switch(value)
{
case "StringA":
...
break;
case "StringB":
...
break;
default:
throw new ArgumentException("Invalid argument");
}
}