首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

大神帮忙,刚刚学C

2013-12-30 
大神帮忙,刚学C#using Systemusing System.Collections.Genericusing System.Textusing System.Reflect

大神帮忙,刚学C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ch1226FanShe
{
    class Program
    {
        public static void Main(string[] args)
        {
            string testclass = "System.Refection.ProperInfo";
            Console.WriteLine("\nFollowing is the member info for class: {0}",
                                            testclass);
            Type MyType = Type.GetType(testclass);//存储类型的类型
            //MemberInfo [] Mymemberinforra = MyType.GetMembers();//获取类型包含的成员
            MemberInfo[] Mymemberinforray = MyType.GetMembers();
            Console.WriteLine("\nThere are {0} members in {1}",
                                        Mymemberinforray.GetLength(0),
                                        MyType.FullName);
            for (int counter = 0; counter < Mymemberinforray.GetLength(0); counter++)
            {
                Console.WriteLine("{0}--{1}  Member type --{2}",
                                               counter, Mymemberinforray[counter].Name,
                                               Mymemberinforray[counter].MemberType.ToString());
            }
        }
    }
}
会报错误:
 未处理的异常:  System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 ch1226FanShe.Program.Main(String[] args) 位置 E:\C#\ch1226FanShe\ch1226Fan
She\Program.cs:行号 16
怎么修改……
[解决办法]
自己查哪个对象为null,找到了自己解决
[解决办法]
刚学 C# 连断点调试都没学,就开始搞反射…………如果是书上抄的代码,书上前几章没教你断点调试?
[解决办法]
打个断点调试啊,不要慌张
[解决办法]
Type.GetType(testclass);//存储类型的类型  你改为: Type MyType = testclass.GetType();// 
试试

热点排行