如题 求教————————
请测试以下代码
using System;
using System.Collections.Generic;
using System.Text;using System.Reflection;
namespace BubbleSort.io
{
public class ReflectionHelper
{
private Data data = new Data();
public void ListMember()
{
Console.WriteLine("-----遍历反射对象-----");
Console.WriteLine("成员名\t\t成员类型\t\t声明成员类");
MemberInfo[] arr = data.GetType().GetMembers();
foreach (MemberInfo var in arr)
{
Console.WriteLine(string.Format("{0}\t{1}\t{2}", var.Name.PadRight(10, ' '), var.MemberType.ToString().PadLeft(10, ' '), var.DeclaringType.ToString().PadLeft(10, ' '))); } }
public void ListScore()
{
Console.WriteLine("------成绩数据------");
Console.WriteLine("姓名\t\t性别\t\t课程名\t\t教授\t\t成绩");
FieldInfo[] arr = data.GetType().GetFields();
foreach (FieldInfo var in arr)
{
Score score = (Score)var.GetValue(data);
Console.WriteLine(string.Format("{0},{1},{2},{3},{4}",score.student.studentName,score.student.studentGender,score.course.courseName,score.course.courseTeacherName,score.)); }
}
}
}
public class Data
{
public Score score1;
public Score score2;
public Score score3;
public Score score4;
private Student stu1;
private Student stu2;
private Course cou1;
private Course cou2;
public Student Stu1
{
get { return stu1; }
set { value = stu1; }
}
public Student Stu2
{
get { return stu2; }
set { value = stu2; }
}
public Data()
{ stu1 = new Student("小李",Gender.男);
stu2 = new Student("小明",Gender.女);
cou1 = new Course("课程A","Jession");
cou2 = new Course("课程B","LG");
score1 = new Score(stu1,cou1,90);
score2 = new Score(stu1,cou2,80);
score3 = new Score(stu2, cou1, 100);
score4 = new Score(stu2,cou2,100);
}
public Course GetCourse1()
{
return cou1;
}
public Course GetCourse2()
{
return cou2;
}
}
public enum Gender{男,女}
public class Student
{ public string studentName;
public Gender studentGender; public Student(string nStudentName,Gender nStudentGender)
{
studentName = nStudentName;
studentGender = nStudentGender;
}
}
public class Course
{
public string courseName;
public string courseTeacherName;
public Course(string sCourseName,string sCourseTeacherName)
{
courseName = sCourseName;
courseTeacherName = sCourseTeacherName;
}
}
public class Score
{
public Student student;
public Course course;
public int ;
public Score(Student nStudent,Course nCourse,int nMark)
{
nStudent = student;
nCourse = course;
= nMark;
}
}为什么报出nullflectionExptions的错误来 请大虾详细解释下
请测试以下代码
using System;
using System.Collections.Generic;
using System.Text;using System.Reflection;
namespace BubbleSort.io
{
public class ReflectionHelper
{
private Data data = new Data();
public void ListMember()
{
Console.WriteLine("-----遍历反射对象-----");
Console.WriteLine("成员名\t\t成员类型\t\t声明成员类");
MemberInfo[] arr = data.GetType().GetMembers();
foreach (MemberInfo var in arr)
{
Console.WriteLine(string.Format("{0}\t{1}\t{2}", var.Name.PadRight(10, ' '), var.MemberType.ToString().PadLeft(10, ' '), var.DeclaringType.ToString().PadLeft(10, ' '))); } }
public void ListScore()
{
Console.WriteLine("------成绩数据------");
Console.WriteLine("姓名\t\t性别\t\t课程名\t\t教授\t\t成绩");
FieldInfo[] arr = data.GetType().GetFields();
foreach (FieldInfo var in arr)
{
Score score = (Score)var.GetValue(data);
Console.WriteLine(string.Format("{0},{1},{2},{3},{4}",score.student.studentName,score.student.studentGender,score.course.courseName,score.course.courseTeacherName,score.)); }
}
}
}
public class Data
{
public Score score1;
public Score score2;
public Score score3;
public Score score4;
private Student stu1;
private Student stu2;
private Course cou1;
private Course cou2;
public Student Stu1
{
get { return stu1; }
set { value = stu1; }
}
public Student Stu2
{
get { return stu2; }
set { value = stu2; }
}
public Data()
{ stu1 = new Student("小李",Gender.男);
stu2 = new Student("小明",Gender.女);
cou1 = new Course("课程A","Jession");
cou2 = new Course("课程B","LG");
score1 = new Score(stu1,cou1,90);
score2 = new Score(stu1,cou2,80);
score3 = new Score(stu2, cou1, 100);
score4 = new Score(stu2,cou2,100);
}
public Course GetCourse1()
{
return cou1;
}
public Course GetCourse2()
{
return cou2;
}
}
public enum Gender{男,女}
public class Student
{ public string studentName;
public Gender studentGender; public Student(string nStudentName,Gender nStudentGender)
{
studentName = nStudentName;
studentGender = nStudentGender;
}
}
public class Course
{
public string courseName;
public string courseTeacherName;
public Course(string sCourseName,string sCourseTeacherName)
{
courseName = sCourseName;
courseTeacherName = sCourseTeacherName;
}
}
public class Score
{
public Student student;
public Course course;
public int ;
public Score(Student nStudent,Course nCourse,int nMark)
{
nStudent = student;
nCourse = course;
= nMark;
}
}为什么报出nullflectionExptions的错误来 请大虾详细解释下
解决方案 »
- 我得vs2008,设计页面打不开,一点vs就死了,动不了,不知道是什么原因
- 一个关于GridView中DropDownList的OnSelectedIndexChanged 翻页刷新问题 请大家帮忙
- 图片存入数据库后,在调出来打印为什么比直接打印图片要小?
- QQ面板上的四个按钮(QQ好友、通讯录、QQ群、最近联系人)的完整代码,用C#写。。
- 如何捕捉系统MESSAGE并且直接让他前确定
- 又一个简单的数据查询语句,帮帮忙!
- C#声明数组
- 请教做winform程序时候的架构设计
- 高分求C#大文件上传组件开发的解决方法.
- datagrid中全选和反选的问题?
- 请教winform怎样切换
- C# 文件传输的传输单元控制在多少最宜
public Score(Student nStudent,Course nCourse,int nMark)
{
student=nStudent ;
course=nCourse ;
=nMark;
}
感谢