文本框变为零(0) [英] textbox turn to zero (0)

查看:124
本文介绍了文本框变为零(0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public double numOfP1, numOfP2, piecePr1, piecePr2, prSub1, prSub2, totalSub;

       private void multiplyButton_Click(object sender, EventArgs e)
       {
           if ((price1.Text == null) || (numOfPiece1.Text == null))
           {
               numOfP1 = Convert.ToDouble(numOfPiece1.Text);
               numOfP1 = 0;
               piecePr1 = Convert.ToDouble(price1.Text);
               piecePr1=0; 
           }
           
           if ((price2.Text == null) || (numOfPiece2.Text == null))
           {
               numOfP2 = Convert.ToDouble(numOfPiece2.Text);
               numOfP2 = 0; 
               piecePr2 = Convert.ToDouble(price2.Text);
               piecePr2 =0; 
           }                  

           prSub2 = piecePr2 * numOfP2;
           priceSub2.Text = prSub2.ToString();
           prSub1 = piecePr1 * numOfP1;
           priceSub1.Text = prSub1.ToString();
       }
   }




我将numOfP1, piecePr1, numOfP2,piecePr2转到0.它们没有作为我在这些文本框中输入的数字出现.

如何使这些文本框显示我键入的数字.

谢谢,




I got numOfP1, piecePr1, numOfP2,piecePr2 turn to 0. They are not appear as the number I enter into these textboxes.

How can I make these textboxes appear the numbers that I typed in.

thanks,

推荐答案

显然,由于您指定为"0",因此它们变为0.仔细看毕竟,始终在调试器下运行此代码.这很简单.

顺便说一句,您原则上编码错误的方式.您倾向于将变量(成员)用于诸如numOfP1, numOfP2, piecePr1, piecePr2, prSub1, prSub2, totalSub之类的临时值.诸如此类的一切都应该是本地的.邀请您进行错误和无用的内存分配的操作.

—SA
Apparently, they turn turn 0 because you assign "0". Look thoroughly. After all, run this code under debugger, always do. It is very simple.

By the way, you are coding wrong way in principle. You tend to use variable (members) for temporary values like numOfP1, numOfP2, piecePr1, piecePr2, prSub1, prSub2, totalSub. Everything like that should be local; what you do in invitation for bugs and useless allocation of memory.

—SA


这篇关于文本框变为零(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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