日期:2014-05-17  浏览次数:20959 次

大神帮忙,刚学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
怎么修改……