代码如下:
using System;
using System.Collections.Generic;
using System.Text;namespace 属性
{
    public class employeeInfo
    {
        private string _company;
        public string employeeCompany
        {
            get { return _company; }
            set { _company = value; }
        }        private int _age;//寄存年龄的字段
        public int employeeAge//年龄属性
        {
            get { return _age; }
            set { _age = value; }
        }        private string _name;//寄存姓名的字段
        public string employeeName//姓名属性
        {
            get { return _name; }
            set { _name = value; }
        }        private string _gender;      
        public string employeeGender
        {
            get {return _gender; }
            set { _gender=value; }
        }                       
    }
}
(以上我在一个类库中定义了4个属性,在其他程序中调用都正确运行)using System;
using System.Collections.Generic;
using System.Text;
using 属性;//已经添加了 属性库.dllnamespace 调用属性程序 //调用属性!
{
    
    class Program
    {
        static void 输入显示员工属性(ref employeeInfo[] empNew)
        {
            for (int i = 0; i <=empNew.Length - 1; i++)
            {
                Console.WriteLine("第"+(i+1)+"个员工。");
                Console.WriteLine("输入公司名称:");
                empNew[i].employeeCompany = Convert.ToString(Console.ReadLine());//属性的写入
                Console.WriteLine("输入姓名:");
                empNew[i].employeeName = Convert.ToString(Console.ReadLine());//属性的写入
                Console.WriteLine("输入性别:");
                empNew[i].employeeGender = Convert.ToString(Console.ReadLine());//属性的写入
                Console.WriteLine("输入年龄:");
                empNew[i].employeeAge = Convert.ToInt16(Console.ReadLine());//属性的写入
                Console.WriteLine("公司:" + empNew[i].employeeCompany + " 姓名:" + empNew[i].employeeName + " 性别:" + empNew[i].employeeGender + " 年龄:" + empNew[i].employeeAge);
            }
        }        static void Main(string[] args)
        {            
            Console.Write("输入员工数目:");
            int x = Convert.ToInt16(Console.ReadLine());
            employeeInfo[] empNew = new employeeInfo[x];
            输入显示员工属性(ref empNew);         
            
            Console.ReadKey();
        }
    }}
运行时提示在               
empNew[i].employeeCompany = Convert.ToString(Console.ReadLine());处提示“未处理”“未将对象引用设置到对象的实例。”
如下图显示: 
请大家帮我调试一下代码,使得他能正确运行。希望大家把正确的代码附上。谢谢ORZ

解决方案 »

  1.   

    1。没分
    2。结贴率0%
    3。方法名,命名空间,程序集都使用汉字
    static void Main(string[] args)
            {           
                Console.Write("输入员工数目:");
                int x = Convert.ToInt16(Console.ReadLine());
                employeeInfo[] empNew = new employeeInfo[x];
    for(int i=0;i<x;i++)
    {
    empNew = new employeeInfo();
    }
                输入显示员工属性(empNew);       
               
                Console.ReadKey();
            }