请教VS2010+ASP.NET编写网站,网站中建立一个类,类中有方法,网站中引用这个类中的方法

山东蓝鸟贵薪 2023-05-16 11:14:12

请教VS2010+ASP.NET+net2.0版本的编写网站,网站中建立一个类,类中有方法,网站中引用这个类中的方法

asp.net 文件说明 

1)类文件Student.cs代码如下:

using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
///Student 的摘要说明
/// </summary>

 public class Student
 {
        public string brand;
        private double cash;

        public int intA; //定义int类型字段
        public string strA; //定义string类型字段

        //年龄  0个引用 
        public int Age
        {
            get
            {
                return this.Age;
            }

            set
            {
                this.Age = value;
            }
        }

        //姓名  0个引用
        public string Name
        {
            get
            {
                return this.Name;
            }

            set
            {
                this.Name = value;
            }
        }

        public Student()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
            brand = "杂牌";    
        }

        public double cashCount() 
        {
            return cash;
        }
 }

========================================

2)主网页前端:default.aspx界面如下:

 

3)后端代码:default.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

 public partial class _Default : System.Web.UI.Page  
{
        protected void Page_Load(object sender, EventArgs e)
        {
            Student stud = new Student(); //实体化类

            stud.Name = "小明";   //赋值 姓名为:小明
            stud.Age = 22;        //赋值 年龄为:22

            //取值信息
            //Response.Write(" 姓名: " + stud.Name.ToString());
            //Response.Write(" 年龄: " + stud.Age.ToString());

            Label_name.Text = stud.Name.ToString();
             Label_age.Text = stud.Age.ToString();

            stud.brand = "爱马仕";
            //Response.Write( stud.brand) ;//brand 为自定义公共属性,cash这一私有属性不会被看到;
            //Response.Write( stud.cashCount() );//cashCount为自定义方法;

            Label_other_info.Text = stud.brand.ToString() + stud.cashCount().ToString();

        }
}
==========================================

调试错误如下:

 

请问错误在什么地方?如何解决???

 

 

...全文
205 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

663

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder Web 应用
社区管理员
  • Web 应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧