大神帮忙,刚学C#

西C 2013-12-27 09:15:22
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
怎么修改……
...全文
187 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
西C 2013-12-30
  • 打赏
  • 举报
回复
引用 9 楼 Theflybird 的回复:
Type.GetType(testclass);//存储类型的类型 你改为: Type MyType = testclass.GetType();// 试试
小恒丶 2013-12-27
  • 打赏
  • 举报
回复
f9 f5 f10
MrLeft 2013-12-27
  • 打赏
  • 举报
回复
打个断点调试啊,不要慌张
欢乐的小猪 2013-12-27
  • 打赏
  • 举报
回复
F5 F9 F10 F11
Persistence_x 2013-12-27
  • 打赏
  • 举报
回复
System.NullReferenceException: 未将对象引用设置到对象的实例 80%由于是null
youzelin 2013-12-27
  • 打赏
  • 举报
回复
刚学 C# 连断点调试都没学,就开始搞反射…………如果是书上抄的代码,书上前几章没教你断点调试?
Benjay77 2013-12-27
  • 打赏
  • 举报
回复
断点调试 会有提示是哪个为NULL
bdmh 2013-12-27
  • 打赏
  • 举报
回复
自己查哪个对象为null,找到了自己解决
Theflybird 2013-12-27
  • 打赏
  • 举报
回复
Type.GetType(testclass);//存储类型的类型 你改为: Type MyType = testclass.GetType();// 试试
  • 打赏
  • 举报
回复
f11 断点试试看

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧