主题:请问程序那里有问题,似乎是异常
输入完数据后,弹框
显示
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“I:\Person\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_zh-CHS_b77a5c561934e089\mscorlib.resources.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll”
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll”
线程 0xa2c 已退出,返回值为 0 (0x0)。
线程 0x3b0 已退出,返回值为 0 (0x0)。
线程 0x8d0 已退出,返回值为 0 (0x0)。
“ConsoleApplication1.vshost.exe”(托管): 已加载“I:\Person\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe”,符号已加载。
在 System.NullReferenceException 中第一次偶然出现的“ConsoleApplication1.exe”类型的异常
未处理的“System.NullReferenceException”类型的异常出现在 ConsoleApplication1.exe 中。
其他信息: 未将对象引用设置到对象的实例。
“ConsoleApplication1.vshost.exe”(托管): 已加载“C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll”
线程 'vshost.RunParkingWindow' (0xcf0) 已退出,返回值为 0 (0x0)。
程序“[2292] ConsoleApplication1.vshost.exe: 托管”已退出,返回值为 -1073741819 (0xc0000005)。
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Person //定义人类
{
string name;
char sex;
int age;
public void SetPerson(string a,char b,int c) //设置人属性
{
name = a;
sex = b;
age = c;
}
public void DisplayPerson() //输出人属性
{
Console.WriteLine("姓名:"+name+" "+"性别:"+sex+" "+"年龄:"+age);
}
}
public class Teacher : Person //定义子类 教师
{
string zhicheng;
string keshi;
string kecheng;
public void SetTeacher(string aa, string bb, string cc) //输入教师属性
{
zhicheng = aa;//职称
keshi = bb;//课室
kecheng = cc;//课程
}
public void DisplayTeacher() //输出教师属性
{
Console.WriteLine("教师职称:" + zhicheng + "教师教研室:" +keshi + "教师授课课程:" + kecheng);
}
}
public class Student : Teacher //定义子类 学生
{
string special;
string classes;
string style;
const int n = 10; //数组大小
public void SetStudent(string aaa, string bbb, string ccc) //设置学生属性
{
special = aaa;//专业
classes = bbb;//班别
style = ccc;//类型
}
public void DisplayStudent() //输出学生属性
{
Console.WriteLine("学生专业:" + special+ "学生班级:" +classes + "学生类别:" + style);
}
static void Main(string[] args)
{
int i,j=-1,k=-1,C;
char B; //性别使用变量
string A, D, E, F;
Console.WriteLine("输入1输入教师信息,输入2输入学生信息,输入3退出!");
i = Convert.ToInt16(Console.ReadLine());
Teacher[] teacher = new Teacher[n]; //定义教师数组
Student[] student = new Student[n]; //定义学生数组
while (true)
{
switch(i)
{
case 1:
j++;
Console.WriteLine("请输入教师的姓名,性别,年龄,职称,教研室,授课课程:(每输入一个属性回车)");
A = Console.ReadLine(); //输入属性
B = Convert.ToChar( Console.ReadLine());
C = Convert.ToInt16( Console.ReadLine());
D = Console.ReadLine();
E = Console.ReadLine();
F = Console.ReadLine();
teacher[j].SetPerson(A, B, C);
teacher[j].SetTeacher(D,E,F);
break;
case 2:
k++;
Console.WriteLine("请输入学生的姓名,性别,年龄专业,班级,类别:(每输入一个属性回车)");
A = Console.ReadLine();
B = Convert.ToChar(Console.ReadLine());
C = Convert.ToInt16(Console.ReadLine());
D = Console.ReadLine();
E = Console.ReadLine();
F = Console.ReadLine();
student[k].SetPerson(A,B,C);
student[k].SetStudent(D,E,F);
break;
default: break;
}
if (i == 3)
break;
}
if (j != -1)
for (i = 0; i < j; i++)
{
teacher[i].DisplayPerson();
teacher[i].DisplayTeacher();
}
else
Console.WriteLine("没有输入教师信息!");
if (k != -1)
for (i = 0; i < j; i++)
{
student[i].DisplayPerson();
student[i].DisplayStudent();
}
else
Console.WriteLine("没有输入学生信息!");
Console.Read();
}
}
}