I've never used switch case
instead of if/else if
, and I'm wondering how to use it. I would really appreciate the help! The task is to put in an amount of wind in a textbox(tbVindstyrke) and the code should tell the user what amount of Watt per hour(W/t) the wind is generating, in a windmill. It should post the result in a label (lbWattprodusert).
I have got it to work with an if
-statement, put as I have understood, this takes up a lot of the computers processioning power (or something). So, I would like to switch it up to a switch
-statement.
double Vs = 0;
private void btSjekkW_Click(object sender, EventArgs e)
{
Vs = Convert.ToDouble(tbVindstyrke.Text);
if (Vs >= 0 && Vs <= 2.4)
lbWattProdusert.Text = 0 + " W/t";
else if (Vs >= 2.5 && Vs <= 3.3)
lbWattProdusert.Text = 2 + " W/t";
else if (Vs >= 3.4 && Vs <= 5.4)
lbWattProdusert.Text = 10 + " W/t";
}