已有56人关注
代码和实例一样为什么运行不了
发表在C#图书答疑 2009-02-13
是否精华
版块置顶:
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Test02
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        partial class account //分部类第一部分
        {
            public int addition(int a, int b) //创建一个整型方法
            {
                return a + b; //方法中的加法运算
            }
        }
        partial class account //分部类第二部分
        {
            public int multiplication(int a, int b) //创建一个整型方法
            {
                return a * b; //方法中的乘法运算
            }
        }
        partial class account  //减法
        {
            public int subtration(int a,int b)
            {
                return a-b; 
            }
        }
        partial class account //除法
        {
            public int division(int a, int b)
            {
                return a / b;
            }
        }        
        private void Form1_Load(object sender, EventArgs e)
        {
             /*
               comboBox1.Items.Add("加");
               comboBox1.Items.Add("减");
               comboBox1.Items.Add("乘");
               comboBox1.Items.Add("除");
            */
            comboBox1.SelectedIndex = 0;
            comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                account at = new account();
                int M = int.Parse(txtNo1.Text.Trim());
                int N = int.Parse(txtNo2.Text.Trim());
                string str = comboBox1.Text;
                switch (str)
                {
                    case "加": txtResult.Text = at.addition(M, N).ToString(); break;
                    case "减": txtResult.Text = at.subtration(M, N).ToString(); break;
                    case "乘": txtResult.Text = at.multiplication(M, N).ToString(); break;
                    case "除": txtResult.Text = at.division(M, N).ToString(); break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
在我的机器上面调试的时候,必须加上已经注释掉的那部分内容才可以,否则的话会提示你SelectedIndex的值是否正确,而我运行自带的实例,则可以正常运行,请给出原因,谢谢!
分享到:
精彩评论 2
shao_fan
学分:0 LV1
2009-02-13
沙发
我用的是vs2008编译器的C#速成版,书是C#从入门到精通。
小科_mrkj
学分:43 LV2
2009-02-13
板凳
读者朋友:
    您好,因为我们的书上在ComboBox控件的Items属性中已经添加了这几项,您需要在窗体设计器中添加那几项,然后就可以正常运行了。
首页上一页 1 下一页尾页 2 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照