相关疑难解决方法(0)

初始化锯齿状数组

我想用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)

.net c# jagged-arrays

18
推荐指数
3
解决办法
2万
查看次数

初始化其他类的对象?

我有一个有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类中删除构造函数后,同样的错误仍然存​​在.

c# class list object

0
推荐指数
1
解决办法
53
查看次数

标签 统计

c# ×2

.net ×1

class ×1

jagged-arrays ×1

list ×1

object ×1