663
社区成员




请教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();
}
}
==========================================
调试错误如下: