private void updateButton_Click(object sender, EventArgs e)
{
//custID.Text = customers[id].ID.ToString();
customers[id].Name = custName.Text.ToString();
customers[id].Suburb = custSuburb.Text.ToString();
customers[id].Balance = custBal.Text;
customers[id].Year_used = custYear.Text;
}
}
public class Customer
{
protected string id;
protected string name;
protected string suburb;
protected double balance;
protected double year_used;
public string ID
{
get { return id; }
}
public string Name
{
get { return name; }
set { value = name; }
}
public string Suburb
{
get { return suburb; }
set { value = suburb; }
}
public double Balance
{
get { return balance; }
set { value = balance; }
}
public double Year_used
{
get { return year_used; }
set { value = year_used; }
}
public Customer(string id, string name, string suburb, double balance, double year_used)
{
this.id = id;
this.name = name;
this.suburb = suburb;
this.balance = balance;
this.year_used = year_used;
}
}
似乎我得到這個錯誤,當我嘗試運行代碼?似乎是什麼問題,我改變了一切,有詮釋翻番。不能隱式地將類型'字符串'轉換爲'double'問題
除了:
customers[id].Balance = custBal.Text;
customers[id].Year_used = custYear.Text;
什麼是對custBal正確的代碼。和custYear。使其顯示在我的表單上?有任何想法嗎?
你可以擺脫。ToString()上的ID,名稱和郊區分配。您將字符串(.Text)分配給字符串屬性。還要考慮驗證 - 如果無法提交沒有有效餘額和年份的表單,那就沒問題。但除此之外,請查看[double.TryParse()](http://msdn.microsoft.com/en-us/library/system.double.tryparse.aspx)。 – Michael