我正在尝试在 Visual Studio 2010 中编译有关数组和类的代码,但是在运行它时遇到问题(consoleapplication.Carray 不包含采用 0 个参数的构造函数)正在显示,有人可以告诉我我错了吗做代码只显示和数组,或者有什么办法可以做到吗????代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
CArray CArray;
CArray nums = new CArray();
for (int i = 0; i <= 49; i++)
nums.insert(i);
nums.displayElements();
}
}
class CArray
{
private int[] arr;
private int upper;
private int numElements;
public CArray(int size)
{
arr = new int[size];
upper = size - 1;
numElements = 0;
}
public void insert(int item)
{
arr[numElements] = item;
numElements++;
}
public void displayElements()
{
for (int i = 0; i <= upper; i++)
Console.Write(arr[i] + " ");
}
public void clear()
{
for (int i = 0; i <= upper; i++)
arr[i] = 0;
numElements = 0;
}
}
}