Ich habe versucht, diesen Code unten zu einer switch-Anweisung zu konvertieren, aber meine Fähigkeiten sind nicht perfekt in C#. Könnte mir bitte jemand mit diesem Fall helfen?Convert Wenn Anweisung zu wechseln
protected void logobtn_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = Request.Cookies.Get("Location");
if (cookie["Location"] == null ||
cookie["Location"].ToString() == null ||
cookie["Location"].ToString() == "" ||
cookie["Location"].ToString() == "-- Europe and Eastern Europe --" ||
cookie["Location"].ToString() == "-- Asia & South-East Asia --" ||
cookie["Location"].ToString() == "-- North & South of America --"
) {
Response.Redirect("Index.aspx");
} else {
Response.Redirect(string.Format("Berava.aspx?Country={0}", cookie.Value));
}
}
Braucht es eine Case-Anweisung zu sein? Sieht gut aus, wie es ist, ein Fall kann es ausführlicher machen, als es sein muss, da Sie die gleiche Aktion für viele der Optionen ausführen. –