How to eliminate "else-if" statements.
- by Stremlenye
My function get QueryString from some Web page as a string.
I need to parce it, to check, what strategy i must use.
Now my code looks ugly (i think so):
public QueryStringParser(string QueryString)
{
if (string.IsNullOrEmpty(QueryString))
{
this._mode = Mode.First;
}
else if (QueryString.Contains(_FristFieldName) && !QueryString.Contains(_SecondFieldName))
{
this._mode = Mode.Second;
}
else if (!QueryString.Contains(_FristFieldName) && QueryString.Contains(_SecondFieldName))
{
this._mode = Mode.Third;
}
else
{
throw new ArgumentException("QueryString has wrong format");
}
}
There must'n't be both FieldNames in one QueryString.
How to change this code to be mo readable.