【发布时间】:2016-03-07 00:03:58
【问题描述】:
这应该有效,因为尽管被声明为最后一个私有双精度,但 C# 的模块化应该也允许识别第一个 CalcTotalChargs。这使我无法成功运行程序
这是我目前的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Adam_Zeidan_HW7CH6_6_Hospital_Stay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
*label6.Text = "You will be paying: " + **CalcTotalChargs()**.ToString("c");*
}
private int CalcStayCharges()
{
return (350 * int.Parse(textBox1.Text)); // Calculating the amount of days by $350
}
private double CalcMiscCharges()
{
return double.Parse(textBox2.Text) + double.Parse(textBox3.Text) +
double.Parse(textBox5.Text) + double.Parse(textBox5.Text); // Adding together the other values entered within the textboxes to add to the eventual total charge
}
private double CalcTotalCharges()
{
return CalcMiscCharges() + CalcStayCharges(); // Adding the number value of the sum of the previous calculation to the sum of the 350 * Number of days staying
}
}
}
【问题讨论】:
-
你能提供一个错误吗?就目前而言,您的代码对我来说很好,我无法重现该问题(如果有的话)。
-
没问题!错误出现在 "label6.Text = "You will pay: " + CalcTotalChargs().ToString("c");" 行中Visual Studio C# 无法识别 CalcTotalChargs() 并说它在当前上下文中不存在。
标签: c# linq variables calculator