C#.NET中的定义类成员(属性)(关键字get,set)

/*
 * Created by SharpDevelop.
 * User: noo
 * Date: 2009-8-16
 * Time: 16:22
 * 
 * 定义类成员(属性),所有的成员都有自己的访问级别,public,private(默认),internal(项目内部),protected(类、派生类)
 * 公共关键字static(静态成员)
 
*/

using System ;
class propertiesA
{
    
private string name;
    
public string Name
    {
        
get{return this.name;}//
        set//
        {
            
this.name =value;
        }
    }
    
public void output()
    {
        Console.WriteLine (
"这个人的姓名是:"+name);
    }
}
class Test
{
    
static void Main()
    {
        propertiesA a
=new propertiesA ();
        a.Name 
="吴宝佑";//写入属性
        a.output ();
    }
}
posted @ 2009-08-16 18:48  爱生活,爱GIS  阅读(765)  评论(0编辑  收藏  举报