数组使用的问题

Posted on 2004-09-22 21:23  鲁旭  阅读(881)  评论(1编辑  收藏  举报
using System;

namespace ArrayTest
{
    
/// <summary>
    
/// test 的摘要说明。
    
/// </summary>

    public class test
    
{

        
public static void Main()
        
{
            myArray[] myArrayTest
=new myArray[6];
            
for (int i=0;i<6;i++)
                Console.WriteLine(
"name:"+myArrayTest[i].name);
            Console.ReadLine();
        }

    }

    
public class myArray
    
{
        
public string name;
        
public myArray()
        
{
            name
="luxv";
        }


    }

}

此程序运行时提示 未将对象引用设置到对象的实例,我想问一下 类myArray的数组不能这样声明吗?还是哪里没有初始化?


哈哈 我自己搞定了  ,果然是在c#里这样声明 myArray[] myArrayTest=new myArray[6];数组不会调用构造函数,就不会分配内存。搞定

Copyright © 2024 鲁旭
Powered by .NET 8.0 on Kubernetes