C#类的认识

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Class_property
{
    class Program
    {
        static void Main(string[] args)
        {
            Person Person1 = new Person("Jack", 20);
            Person1.ID = 001;
            //Person1.age = 15; 由于age,name为私有属性 所以不可访问

            Person1.ShowPersonInfo();
            Console.WriteLine("Count:{0}", Person.count);//切记 由于Count 为静态属性调用的时候调用父类来调用 静态成员调用的时候要注意
            Console.Read();


        }
        public class Person//类后面不带括号
        {
            public int ID;//公有成员;
            protected int age;//保护成员age;
            private string name;//私有成员;
            public static int count;//静态成员
            //公共成员,构造函数
            public Person(string names, int agee)
            {
                this.name = names;//正确,允许访问自身成员
                this.age = agee;//正确,允许访问自身成员
                count++;//自加
            }
            public void ShowPersonInfo()
            {
                Console.WriteLine("Name:{0} \t Age:{1}", name, age);//这是类的属性
            }

 

 

        }
    }
}

对于C#的类  调用静态方法,调用父类.静态方法;
对于动态方法,需要建立类的实例 通过实例.动态方法来调用

posted @ 2013-03-06 16:04  啸月☆天狼  阅读(118)  评论(0编辑  收藏  举报