C#中所涉及的“封装”到底指什么,您真的知道吗?
2019-08-04 本文已影响0人
一位热爱文学的程序员
1、属性封装
private int _Age;
public string Age{
get{
return _Age;
}
set{
if(value>1000&&value<1200){
_Age = value;
}
}
-------------------------------------------------------------------
2、函数传递参数进行封装
func(string a,string b ,string c){
funca(string a,string b ,string c){}
}
改造后=》
class student{
public string a;
public string b;
public string c;
}
Func(new student(){a=“1”,b=“2”,c=“3”});
func(student student){
funca(student student){
}
}
-------------------------------------------------------------------
3、右键重构可以提取到新的方法中去