为什么这段代码不会执行? [英] Why won't this code execute?

查看:83
本文介绍了为什么这段代码不会执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void convertButton_Click(object sender, EventArgs e)
        {
          
            const int FEET = 5820;
            string label2;
            int result;
            int miles;

            miles = Convert.ToInt32 (textBox1.Text);
            result = miles * FEET;
            

            label2 =  ("The equivalent in feet is. "  + result);

        }
    }
}

推荐答案

1。如果代码不会首先执行错误。它会告诉你究竟是什么问题。

2.您只需快速浏览一下就可以将标签设置为字符串。你想设置label2的.Text。



1. If code won't execute first start with the error. It will tell you exactly what the problem is.
2. Just at a quick glance you are trying to set a label to a string. You want to set the .Text of the label2.

label2.Text =  "The equivalent in feet is. "  + result;





或者你可以这样做:



or you can do like this:

label2.Text =  String.Format("The equivalent in feet is. {0}", result);


您的代码不会为用户产生可观察的效果:您正在为本地字符串分配值。尝试为控件分配相同的值(例如,为 TextBox.Text 属性)
Your code doesn't produce observable effects for the user: you are assigning a value to a local string. Try to assign the same value to a control (for instance to a TextBox.Text property)


这篇关于为什么这段代码不会执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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