VS 2015的C#问题。如果是,如何实现if else [英] C# question for VS 2015. How to implement if else if

查看:163
本文介绍了VS 2015的C#问题。如果是,如何实现if else的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的程序,它是一个类赋值。我无法弄清楚如何结束代码。



我尝试过:



I am making a simple program that is a class assignment. I cannot figure out how to wrap up the code.

What I have tried:

public partial class frmPetClinic : Form
    {

 public frmPetClinic()
        {
            InitializeComponent();

            // Delcare varibles.

            Boolean bolFleaTreatment;
            Boolean bolHairTrim;
            Boolean bolNailTrim;
            Boolean bolDematting;
            Boolean bolHeartwormTreatmen;
            Boolean bolHepatitisVaccine;
            Boolean bolDistemperVaccine;
            Boolean bolRabiesVaccine;

            double dblCost;

            bolFleaTreatment = chkFleaTreatment.Checked;
            bolHairTrim = chkHairTrim.Checked;
            bolNailTrim = chkNailTrim.Checked;
            bolDematting = chkDematting.Checked;
            bolHeartwormTreatmen = chkHeartwormTreatment.Checked;
            bolHepatitisVaccine = chkHepatitisVaccine.Checked;
            bolDistemperVaccine = chkDistemperVaccine.Checked;
            bolRabiesVaccine = chkRabiesVaccine.Checked;

            dblCost = 0;

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            //Exit the app.

            Application.Exit();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            //Clear selected checkboxes.
            //Clear running total.

            chkFleaTreatment.Checked = false;
            chkHairTrim.Checked = false;
            chkNailTrim.Checked = false;
            chkDematting.Checked = false;
            chkHeartwormTreatment.Checked = false;
            chkHepatitisVaccine.Checked = false;
            chkDistemperVaccine.Checked = false;
            chkRabiesVaccine.Checked = false;

            lblCost.Text = string.Empty;
        }

        private void chkFleaTreatment_CheckedChanged(object sender, EventArgs e)
        {

            // Decide which if any checkboxes are checked.
            // Add total costs and convert to currency

            // If box is unchecked, deduct price from cost
            if
                (true)

                
            else
                
        }
          

    }
        
}

推荐答案

基于你的代码这样的事情应该是伎俩。一旦你把所有东西都搞定了,那就想想如何改进它,或者把它缩短。



based on the code you presented something like this should do the trick. Once you get everything working, then think of how to improve it, or make it shorter.

public partial class frmPetClinic : Form
    {
double currentTotal = 0;
        double fleaTreatment = 112.5;
        double hairTrim = 88;
        System.Globalization.NumberStyles style =   System.Globalization.NumberStyles.Number | 
                                                    System.Globalization.NumberStyles.AllowCurrencySymbol;
        System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

        private void chkFleaTreatment_CheckedChanged(object sender, EventArgs e)
        {
            
            double.TryParse(lblCost.Text, style, culture, out currentTotal);

            if (chkFleaTreatment.Checked)
            {
                lblCost.Text = Math.Round(currentTotal + fleaTreatment, 2).ToString("C2");
            }
            else
            {
                lblCost.Text = Math.Round(currentTotal - fleaTreatment, 2).ToString("C2");
            }
        }

        private void chkHairTrim_CheckedChanged(object sender, EventArgs e)
        {
            double.TryParse(lblCost.Text, style, culture, out currentTotal);

            if (chkHairTrim.Checked)
            {
                lblCost.Text = Math.Round(currentTotal + hairTrim, 2).ToString("C2");
            }
            else
            {
                lblCost.Text = Math.Round(currentTotal - hairTrim, 2).ToString("C2");
            }
        }

//private void chkNailTrim_CheckedChanged(object sender, EventArgs e)
//...

}


这篇关于VS 2015的C#问题。如果是,如何实现if else的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆