C#----Get和Set在属性中的使用
来源:互联网 发布:k速电子狗升级软件 编辑:程序博客网 时间:2024/05/01 19:19
Get和Set在属性中的作用:
第一个作用:保证数据的安全性,对字段进行了有效的保护。
第二个作用:起到监视作用
private int width=0;public int Width{ get{return width;} set{width=value*2;}}可以监视字段的变化,在Set中使用private int width=0;public int Width{ get{return width;} set { //Do something width=value; }} private int width = 1; public int Width { get { return width*2; } set { Console.WriteLine("变化前:{0}", width); //1 width = value + 2; Console.WriteLine("变化后:{0}", width); //7=5+2 } } static void Main(string[] args) { Program p = new Program(); Console.WriteLine(p.Width); p.Width = 5;//这里width的值不会是5的 Console.WriteLine(p.Width);//14=2*7 Console.WriteLine(p.Width);//14 Console.Read(); }
0 0
- C#----Get和Set在属性中的使用
- C#——关于属性字段中的set和get
- Java 对类中的属性使用set/get方法的意义和用法
- java 中对类中的属性使用set/get方法的意义和用法
- java 中对类中的属性使用set/get方法的意义和用法
- Java中对类中的属性使用set/get方法的意义和用法
- 【C#】 get和set
- C#中的get和set有什么用 声明属性
- C#_属性的封装(get和set)
- 属性,简化get和set
- C# get和set属性
- 关于objective-c中的set和get方法
- 探秘隐藏在对象中的get和set方法
- 【Java】java中的set()和get()方法理解和使用
- C#中的属性(get、set、value)
- c#中的get和set...
- c#中的get和set
- c#中的get和set
- 'cl' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- 照片由模糊到清晰原理图
- Struts2+Spring3.0+hibernate框架搭建步骤
- AndroidManifest.xml补充之:andorid:configChanges
- CDMA版Droid使用电信3G网络详细教程转载
- C#----Get和Set在属性中的使用
- Android职业认知
- 编译时提示[WinRrror 2] 系统找不到指定的文件,运行时提示gcc 不是内部或外部命令,也不是可运行的程序
- mars android开发之六:radioButton与checkbox
- 【C++进阶】深入理解C/C++(2)
- JNI字段描述符[Ljava/lang/String
- 职责链模式
- MySQL基础知识---------BINARY和VARBINARY类型
- AlarmManager类的应用(实现闹钟功能)