How to eliminate "else-if" statements.
Posted
by Stremlenye
on Stack Overflow
See other posts from Stack Overflow
or by Stremlenye
Published on 2010-04-19T09:01:34Z
Indexed on
2010/04/19
9:03 UTC
Read the original article
Hit count: 363
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.
© Stack Overflow or respective owner