项目内有如下三个文件:Default.aspx,Default.aspx.cs,stone.cs。Default.aspx的代码为:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="myweb._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>love</title>
    </head>
<body bgcolor="White">
    <form id="form1" runat="server">
    <div>
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label1" runat="server" Text="长度"></asp:Label>
&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextL" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label2" runat="server" Text="宽度"></asp:Label>
&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextW" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label3" runat="server" Text="厚度"></asp:Label>
&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextH" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
        <asp:Button ID="myButton" runat="server" onclick="myButton_Click" Text="计算结果" />
        <br />
        <br />
        <asp:Label ID="Label6" runat="server" Text="面积"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Sresult" runat="server"></asp:Label>
        <br />
        <asp:Label ID="Label4" runat="server" Text="体积"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="Vresult" runat="server"></asp:Label>
        <br />
        <br />
    </div>
    </form>
</body>
</html> Default.aspx.cs的代码为:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;namespace myweb
{
    public partial class _Default : System.Web.UI.Page
    {
        stone myStone = new stone();
        public int valueL;
        public int valueW;
        public int valueH;
        public string LL;
        public string WW;
        public string HH;
        public int SS;
        public int VV;
        protected void Page_Load(object sender, EventArgs e)
        {        }        protected void myButton_Click(object sender, EventArgs e)
        {
            LL = TextL.Text;
            WW = TextW.Text;
            HH = TextH.Text;
            valueL = Convert.ToInt32(LL);
            valueW = Convert.ToInt32(WW);
            valueH = Convert.ToInt32(HH);
            SS = myStone.myS();
            VV = myStone.myV(valueH);
            Sresult.Text = SS.ToString();
            Vresult.Text = VV.ToString();
        }
    }
stone.cs的代码为:using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;namespace myweb
{
    public class stone
    {
        _Default my_Default;
        public int L;
        public int W;
        public int myL
        {
            get
            {
                return L;
            }
            set
            {
                L = my_Default.valueL;
            }
        }
        public int myW
        {
            get
            {
                return W;
            }
            set
            {
                L = my_Default.valueW;
            }
        }
        public int myS()
        {
            return L * W;
        }
        public int myV(int H)
        {
            return L*W*H;
        }
    }
}
无论长度、宽度、厚度输入什么数值,面积、体积的计算结果都为0!
什么原因?请求指教!

解决方案 »

  1.   

    protected void myButton_Click(object sender, EventArgs e) 
            { 
                LL = TextL.Text; 
                WW = TextW.Text; 
                HH = TextH.Text; 
                valueL = Convert.ToInt32(LL); 
                valueW = Convert.ToInt32(WW); 
                valueH = Convert.ToInt32(HH); 
    myStone.myL=valueL;
    myStone.myW=valueW;

                SS = myStone.myS(); 
                VV = myStone.myV(valueH); 
                Sresult.Text = SS.ToString(); 
                Vresult.Text = VV.ToString(); 
            } 
      

  2.   

    你没给myStone的长,宽,厚赋值啊
    myStone.myL=valueL;
    myStone.myW=valueW;