net学习心得范文

net学习心得范文

ID:48289416

大小:125.48 KB

页数:6页

时间:2019-11-18

net学习心得范文_第1页
net学习心得范文_第2页
net学习心得范文_第3页
net学习心得范文_第4页
net学习心得范文_第5页
资源描述:

《net学习心得范文》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

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

2、icclassclassperson    {    publicclassperson():this(null)    {    }    publicclassperson(stringstrname)    {    name=strname;    }    privatestringname;    privatestringsex;    privateintage;    publicstringname    {    get{returnname;}    set{name=value;}    }

3、    publicstringsex    {    get{returnsex;}    set{sex=value;}    }    publicintage    {    get{returnage;}    set{age=value;}    }    publicvoidsayhello()    {    if(null==name)    console.writeline("helloworld");    else    console.writeline("hello,"+name);  

4、  }    }    }    添加完之后编译生成一下,就会在这个类库项目中的bindebug中有一个classlib.dll文件。然后添加一个控制台应用程序。引入system.reflaction的命名空间。添加的代码如下:    usingsystem;    usingsystem.collections.generic;    usingsystem.linq;    usingsystem.text;    usingsystem.reflection;//添加反射的命名空间    namespacec

5、onsoleapplication4    {    publicclassprogram    {    staticvoidmain(string[]args)    {    console.writeline("列出程序集中的所有类型");    assemblyass=assembly.loadfrom("classlib.dll");    type[]mytype=ass.gettypes();    typeclassperson=null;    foreach(typepinmytype)    

6、{    console.writeline(p.name);    if(p.name=="classperson")    {    classperson=p;    }    }    console.writeline("列出classpersonl类中的所有的方法");    methodinfo[]md=classperson.getmethods();    foreach(methodinfominmd)    {    console.writeline(m.name);    }    cons

7、ole.writeline("实例化classperson类,并调用sayhello方法");    objectobj=activator.createinstance(classperson);    objectobjname=activator.createinstance(classperson,"飞鹰");    methodinfomysayhello=classperson.getmethod("sayhello");    mysayhello.invoke(obj,null);//无参数构造函数 

8、   mysayhello.invoke(objname,null);//有参构造函数    console.readkey();    }    }    }    运行之后的结果是:    列出程序集中的所有类型    classperson    列出classpersonl类中的所有的方法    get_name    set_name

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。