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#的类  调用静态方法,调用父类.静态方法;
对于动态方法,需要建立类的实例 通过实例.动态方法来调用

转载于:https://www.cnblogs.com/xygzs/archive/2013/03/06/2946292.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值