Assuming that the keywords are constant, then it makes more sense that the collection is defined at the class level. The previous solutions have already mentioned that. I just want to add that since C#4 (or 3?) it's possible to initialize the collections directly (as sa has already mentioned above).
a complete class would then look as follows:
static class myClass
{
static Dictionary<string, string> Keywords = new Dictionary<string, string>()
{
{"start", "START" },
{ "int", "DT" },
{"real", "DT"}
};
public static string IsKeyword(string value)
{
return "???";
}
}
I'm a bit confused about the signature of the
IsKeyword
method. for me as a user of the class it doesn't make sense to have a
Is...
method that returns a string, that's why I left the implementation empty.