.Net 里 Get Set 的用法

      My Works 2007-5-15 17:6

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class test_test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    public class my
    {
        private int a;
        public int sub_a
        {
            get
            {
                return a;
            }
            set
            {
                a = value;
            }
        }
        public int mh()
        {
            a=a+1;
            return a;
        }
     
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        my mytext = new my();  //创建一个对象
        mytext.sub_a = 2;         //此对象有一属性 sub_a,  此时用Set将对象属性的值赋于 该类中 的私有变量a
        label1.Text = mytext.mh().ToString() ;   //调用 该类中的mh()方法,处理a ,此时a=3
        //label1.Text = mytext.sub_a.ToString();    //
    }
}

标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}