net学习心得范文.doc_第1页
net学习心得范文.doc_第2页
net学习心得范文.doc_第3页
net学习心得范文.doc_第4页
net学习心得范文.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

net学习心得范文 1.反射:反射是.中的重要机制,通过反射可以在运行时获得.中每一个类型,包括类、结构、委托和枚举的成员,包括方法、属性、事件,以及构造函数等。有了反射,既可以对每一个类型了如指掌。 下面来演示一下反射的实例 (1)新建一个类库项目。在解决方案上单击右键选择添加“新建项目”,在弹出来的框中选择“类库”,在下面名字栏中输入classlib。然后删除class1类,新添加一个类“classperson”,添加如下代码: namespaceclasslib publicclassclassperson publicclassperson():this(null) publicclassperson(stringstrname) name=strname; privatestringname; privatestringsex; privateintage; publicstringname getreturnname; setname=value; publicstringsex getreturnsex; setsex=value; publicintage getreturnage; setage=value; publicvoidsayhello() if(null=name) console.writeline(helloworld); else console.writeline(hello,+name); 添加完之后编译生成一下,就会在这个类库项目中的bindebug中有一个classlib.dll文件。然后添加一个控制台应用程序。引入system.reflaction的命名空间。添加的代码如下: usingsystem; usingsystem.collections.generic; usingsystem.linq; usingsystem.text; usingsystem.reflection;/添加反射的命名空间 namespaceconsoleapplication4 publicclassprogram staticvoidmain(stringargs) console.writeline(列出程序集中的所有类型); assemblyass=assembly.loadfrom(classlib.dll); typemytype=ass.gettypes(); typeclassperson=null; foreach(typepinmytype) console.writeline(); if(=classperson) classperson=p; console.writeline(列出classpersonl类中的所有的方法); methodinfomd=classperson.getmethods(); foreach(methodinfominmd) console.writeline(); console.writeline(实例化classperson类,并调用sayhello方法); objectobj=activator.createinstance(classperson); objectobjname=activator.createinstance(classperson,飞鹰); methodinfomysayhello=classperson.getmethod(sayhello); mysayhello.invoke(obj,null);/无参数构造函数 mysayhello.invoke(objname,null);/有参构造函数 console.readkey(); 运行之后的结果是: 列出程序集中的所有类型 classperson 列出classpersonl类中的所有的方法 get_name set_name get_sex set_sex get_age set_age sayhello tostring equals gethashcode gettype 实例化classperson类,并调用sayhello方法 helloworld hello,飞鹰 2.using的作用 (1)引入命名空间,如:usingsystem。 (2)using别名。 格式:using别名=包括详细命名空间信息的具体的类型 例如:在两个命名空间(namespace1,namespace2)里各有一个myclass类,这时可以这样引入命名空间, usingaclass=namespace1.myclass; usingbclass=namespace2.myclass; 实例化时: aclassmy1=newaclass; bclassmy2=ne

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论