本文介绍了为什么这个c#代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!float publishedMPG1 = -1; float publishedMPG2 = 1; //Need to make sure what was tpyed can be parsed or we will get an exception if (float.TryParse(textBox_PublishedMPG1, out publishedMPG1) && float.TryParse(textBox_PublishedMPG2, out publishedMPG2)) { label_YearlyFuelCost1.Text = "$" + (12000 / publishedMPG1 * 3.50).ToString(); label_YearlyFuelCost2.Text = "$" + (12000/ publishedMPG2 * 3.50).ToString(); } else { label_YearlyFuelCost1.Text = "Parsing Error!"; label_YearlyFuelCost2.Text = "Parsing Error!"; } TryParse的下划线。此代码的目标是将12000除以输入textBox_PublishedMPH1和textBox_PublishedMPH2的内容再乘以3.50,然后在label_YearlyFuelCost1和label_YearlyFuelCost2中显示它们 我尝试了什么: 只是在这里和那里改变一些数字或行,但到目前为止还没有运气。我是C#的初学者,所以非常感谢所有帮助。The TryParse's are underlined. The goal of this code is to take 12000 divided by what was entered into textBox_PublishedMPH1 and textBox_PublishedMPH2 and then multiply them by 3.50, then to display them in the label_YearlyFuelCost1 and label_YearlyFuelCost2What I have tried:Just changing a few numbers or lines here and there but so far no luck. I am a beginner in C# so all help is appreciated.推荐答案 TryParse的下划线。此代码的目标是花费12000 d通过输入textBox_PublishedMPH1和textBox_PublishedMPH2然后将它们乘以3.50然后将它们显示在label_YearlyFuelCost1和label_YearlyFuelCost2 我尝试过: 只是在这里和那里改变一些数字或行,但到目前为止还没有运气。我是C#的初学者,所以感谢所有帮助。The TryParse's are underlined. The goal of this code is to take 12000 divided by what was entered into textBox_PublishedMPH1 and textBox_PublishedMPH2 and then multiply them by 3.50, then to display them in the label_YearlyFuelCost1 and label_YearlyFuelCost2What I have tried:Just changing a few numbers or lines here and there but so far no luck. I am a beginner in C# so all help is appreciated.if (float.TryParse(textBox_PublishedMPG1.Text, out publishedMPG1) && float.TryParse(textBox_PublishedMPG2.Text, out publishedMPG2)){ // ...} 提示:当将鼠标悬停在TryParse(..) - 方法上时,查看Intellisense-popup:它会告诉您它需要字符串作为第一个参数 - 并将鼠标悬停在变量名 textBox_PublishedMPG1 显示它的类型为 TextBox 。Hint: Look at the Intellisense-popup when hovering over the TryParse(..)-method: It will tell you that it expects a string as first argument - and hovering over the variable name textBox_PublishedMPG1 shows you that it's of type TextBox. 这篇关于为什么这个c#代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 17:33
查看更多