摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;/* 属性 * 惯用法,属性开头字母大写,字段开头字母小写 * 只用set或者只有get就可以定义只读或者只写属性(只写的不常见) * 可以为set get设置访问经别 * (.Net3.x)简化set get; public int Age{ get; set; } 适合于set, get 中凤有特殊死搏斗逻辑代码的情况 * * 字段和属性的区别是什么?属性看似字段,不是字段,可以地非法值控制,可以设置只读 * set get块. 阅读全文
摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;/* 成员访问级别 * 字段,方法,属性都可以叫做类的成员,它们都需要定义访问级别,访问级别的用处在于控制成员在哪些些地方可以被访问,这样达到面向对像中"封装"的目的 * * 几个访问级别: public(任何地访都可以访问) private:默认级别,只能由本类中的成员访问 * 还有intemal, protected两个级别,以后会讲 */namespace _2面向对像简介{ class Program { 阅读全文
摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;/* 面向对像概念(*) * 面向对像不是取代面向过程的 * 类,对象。"人"是类,"张三"是"人"这个类的对像,类是抽像的,对象是的,按钮就是类,某个按钮就是对像,对像可以叫做类的实例 * 类就像int, 对像就像10,字段(和类相关的变量),字段就是类的状态,人这个是类的姓名,年龄,身高等字段,类不占内存,对像才占内存 * * 方法,方法就是类能够够执行的动作,比如间好 阅读全文