上面的代码每次使用前并没有实例化,会报错,实例化以下就好了,参考:http://bbs.csdn.net/topics/391938383
c#实例化对象
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace array1
{
public class student
{
public string name = null;
public decimal number;
public string sex = null;
}
class Program
{
static void Main(string[] args)
{
student[] stu = new student[];
for (int i = ; i < ; i++)
{
stu[i] = new student();
Console.WriteLine("请输入姓名:");
stu[i].name = Console.ReadLine();
Console.WriteLine("请输入序号:");
stu[i].number = int.Parse(Console.ReadLine());
Console.WriteLine("请输入性别:");
stu[i].sex = Console.ReadLine();
} Console.ReadKey();
}
}
}