我想用C#创建数组10*10*10 int[][][](不是int[,,]).
我可以写代码:
int[][][] count = new int[10][][];
for (int i = 0; i < 10; i++) {
count[i] = new int[10][];
for (int j = 0; j < 10; j++)
count[i][j] = new int[10];
}
Run Code Online (Sandbox Code Playgroud)
但我正在寻找一种更美好的方式.可能是这样的:
int[][][] count = new int[10][10][10];
Run Code Online (Sandbox Code Playgroud) 我有一个有2个列表的类作为它的数据成员.我想将这些数据成员包含为不同的类对象.
我收到此错误:
"你调用的对象是空的."
请告知什么应该是正确的方法.
class dataPoints
{
public List<double> dataValues;
public List<DateTime> timeStamps;
public dataPoints()
{
this.timeStamps = new List<DateTime>();
this.dataValues = new List<double>();
}
}
//I want an object of dataPoints in this below classs
class wellGraph
{
int seriesAdded;
dataPoints[] graphDataPoints;
public wellGraph(int Entries)
{
this.seriesAdded = 0;
this.graphDataPoints = new dataPoints[Entries];
for(int i=0;i<Entries;i++)
{
graphDataPoints[i].timeStamps = new List<DateTime>();
graphDataPoints[i].dataValues = new List<double>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在dataPoints类中删除构造函数后,同样的错误仍然存在.