关于net学习心得

上传人:公**** 文档编号:560308152 上传时间:2023-12-01 格式:DOCX 页数:5 大小:14.40KB
返回 下载 相关 举报
关于net学习心得_第1页
第1页 / 共5页
关于net学习心得_第2页
第2页 / 共5页
关于net学习心得_第3页
第3页 / 共5页
关于net学习心得_第4页
第4页 / 共5页
关于net学习心得_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《关于net学习心得》由会员分享,可在线阅读,更多相关《关于net学习心得(5页珍藏版)》请在金锄头文库上搜索。

1、关于n学习心得 1反射:反射是.net中的重要机制,通过反射可以在运行时获得nt中每一个类型,包括类、结构、委托和枚举的成员,包括方法、属性、事件,以及构造函数等。有了反射,既可以对每一个类型了如指掌。 下面来演示一下反射的实例(1)新建一个类库项目。在解决方案上单击右键选择添加“新建项目”,在弹出来的框中选择“类库”,在下面名字栏中输入caslib。然后删除cass1类,新添加一个类“classperson”,添加如下代码: naesace classlib publi class lspeso public laspern():ths(nll) ubl clasron(sting te)

2、name = sre; prvate sting name; rvate string se; iate int ge; public tn nam get return nme; set ae =alue; pbi stingx gt rturn sex; set sx alue; ublic int age grtr age; set ae = vaue; pliciahll() if (nllne) csole.itelin(helo old); else cosol.teline(hello, nae); 添加完之后编译生成一下,就会在这个类库项目中的indebug中有一个assibd

3、l文件。然后添加一个控制台应用程序。引入sstm.rfacton的命名空间。添加的代码如下:sngsyem; using sstem.coletions.geneic;usin syemlinq;usin systemt;singyterelcio;/添加反射的命名空间 amspace cnsolealiction pulccass pratati voi main(string ags) consolewritline(列出程序集中的所有类型);ssemby ss= assmbly.ladfrom(classlib.dll); type mytype = a.gettype(); tpcla

4、sprso= ull; fech (tye i mytpe) cons.ieine(.nae); f (me=clasen) cassperon=; conole.relin(列出classprnl类中的所有的方法);metdinfo = cassperon.tmethos(); fach(methodifom in ) nsoeriteine(m.nae); cole.reie(实例化classperson类,并调用sayhll方法); object objactivator.createisne(clserson); bje objm=actiator.creaeinstn(casprso

5、n,飞鹰); metodno mysayhell = clapersngetmetod(hell); sayhello.ivke(obj, nul);/无参数构造函数msayhllonvoke(bjne, null);/有参构造函数console.readkey(); 运行之后的结果是:列出程序集中的所有类型 lssprson列出claspersonl类中的所有的方法 e_nme st_ae get_sex set_sex ge_age st_aesaylo tostig eqals gehashcode gttpe 实例化clsspeon类,并调用ayh方法hllowld hlo,飞鹰 .u

6、si的作用 ()引入命名空间,如:usig sstm。()using别名。格式:usig 别名=包括详细命名空间信息的具体的类型例如:在两个命名空间(nmesae,naesae2)里各有一个myclss类,这时可以这样引入命名空间, usg aclass=nmpa1.mycass; uingbclasnepc2.clas; 实例化时: aclass my1new aclas; bclss my2newbclass; (3)sin定义范围 即时释放资源,在范围结束时处理对象。例如:using(clss1 cls1new clas() 在这个代码段结束时会触发cls1的spose方法释放资源。第 1 页 共 1 页免责声明:图文来源于网络搜集,版权归原作者所以若侵犯了您的合法权益,请作者与本上传人联系,我们将及时更正删除。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 商业计划书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号