.net学习心得

时间:2018-12-31 12:00:00 资料大全 我要投稿

.net学习心得

1.反射:反射是.net中的重要机制,通过反射可以在运行时获得.net中每一个类型,包括类、结构、委托和枚举的成员,包括方法、属性、事件,以及构造函数等,

.net学习心得

。有了反射,既可以对每一个类型了如指掌。

下面来演示一下反射的实例

(1)新建一个类库项目。在解决方案上单击右键选择添加“新建项目”,在弹出来的框中选择“类库”,在下面名字栏中输入classlib。然后删除class1类,新添加一个类“classperson”,添加如下代码:

namespace classlib
{
    public class classperson
    {
        public classperson():this(null)
        {

        }
        public classperson(string strname)
        {
            name = strname;
        }

        private string name;
        private string sex;
        private int age;

        public string name
        {
            get { return name; }
            set { name = value; }
        }

        public string sex
        {
            get { return sex; }
            set { sex = value; }
        }

        public int age
        {
            get { return age; }
            set { age = value; }
        }

        public void sayhello()
        {
            if (null==name)
                console.writeline("hello world");
            else
                console.writeline("hello," + name);  
        }
    }
}

添加完之后编译生成一下,就会在这个类库项目中的bin\debug中有一个classlib.dll文件,

资料共享平台

.net学习心得》(https://www.unjs.com)。然后添加一个控制台应用程序。引入system.reflaction的'命名空间。添加的代码如下:

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.reflection;//添加反射的命名空间

namespace consoleapplication4
{
    public class program
    {
        static void main(string[] args)
        {
            console.writeline("列出程序集中的所有类型");
            assembly ass = assembly.loadfrom("classlib.dll");
            type[] mytype = ass.gettypes();
            type classperson = null;
            foreach (type p in mytype)
            {
                console.writeline(p.name);
                if (p.name=="classperson")
                {

《1》《2》.net学习心得 相关文章:携手助学培训心得读三字经心得体会小学科学教研员培训心得小学英语听课心得学习师德师风心得体会学习于丹论语心得体会2012年师德学习心得体会乡镇教研员培训班学习心得查看更多>> 学习心得体会

【.net学习心得】相关文章:

1.net笔试题

2..net笔试题集合

3..net笔试题超级集合

4.ASP.NET笔试题

5.net笔试题目答案

6.用友笔试题目NET试题

7.一套.net笔试题

8.ASP.NET笔试经验心得