asp.net 实体类的疑问

来源:百度知道 编辑:UC知道 时间:2024/09/19 15:41:54
private void button1_Click(object sender, EventArgs e)
{
product product = new product();
product.TName = productName.Text;
product.TPrice1 = Price1.Text; //这里的双精度浮点的数据类型, 要在Price1.Text做转换吗?
MessageBox.Show(product.addit().ToString());

protduct类文件

public string TGuiGe {
get
{
return this.GuiGe;
}
set
{
this.GuiGe = value;
}
}
public double TPJPrice {
get
{
return this.PJPrice;
}
set
{
this.PJPrice = value;
}
}
public double TPrice1 {
get
{
return this.Price1;
}

强类型 就是指你用的数据容器是强类型的,你用了实体类,就有这个效果。

第一次复职时的转换是必需的,以后你再用实体类中的数据时就不用再转换了。

product.TPrice1 = double.Parse(Price1.Text);

product.TPrice1 = Convert.ToDouble(Price1.Text);

你必须要保证Price1.Text是数字类型的,不然会出异常

要转换

是double的,你给人家按个string,干嘛呢?