-4
for (int i = 2; i < k; i++)
{
    if ((tabl1[i].y != null) && (tabl[i].x != null))
    {
        double[] y2 = { 0, tabl1[i].y };
        double[] x2 = { tabl[i].x, 0 };
        PointPairList spl3 = new PointPairList(x2, y2);
    }
}

我想要什么时候i=3创建

double[] y3 = { 0, tabl1[i].y }; 
double[] x3 = { tabl[i].x, 0 }; 
PointPairList spl3 = new PointPairList(x3, y3);

i=4然后创建

double[] y4 = { 0, tabl1[i].y };
double[] x4 = { tabl[i].x, 0 }; 
PointPairList spl4 = new PointPairList(x4, y4);

i=5然后创建

double[] y5 = { 0, tabl1[i].y };
double[] x5 = { tabl[i].x, 0 };
PointPairList spl5 = new PointPairList(x5, y5);

ETC..

4

3 回答 3

1

问题绝对不是克莱尔……像这样?

private static Dictionary<String, PointPairList> s_PointPairLists = new Dictionary<String, PointPairList>();

private static void BuildPointPairLists(Int32 limit)
{
    for (Int32 i = 2; i < limit; ++i)
    {
        if ((tabl[i].x != null) && (tabl[i].y != null))
        {
            Double[] x = { 0, tabl[i].y };
            Double[] y = { tabl[i].x, 0 };

            s_PointPairLists[("ppl" + i.ToString())] = new PointPairList(x, y);
        }
    }
}

public static PointPairList(Int32 index)
{
    String reference = "ppl" + index.ToString();

    if (s_PointPairs.Contains(reference))
        return s_PointPairs[reference];

    return null;
}
于 2013-01-13T21:49:02.290 回答
0

把它变成一个函数并调用它:

public PointPairList GetPointPairList(int index) {
    if (tabl[index].y != null && tabl[index].x != null) {
        double[] x = { 0, tabl[index].y };
        double[] y = { tabl[index].x, 0 };
        return new PointPairList(x, y);
    }
    return null;
}

// ...
for (int i = 2; i < k; i++) {
    PointPairList ppl = GetPointPairList(i);
    // ...
}

这不符合您的要求吗?没有更多的上下文很难说..

于 2013-01-13T21:36:01.660 回答
0

您应该考虑使用Dictionary

var dict = new Dictionary<int, PointPairList>();
for (int i = 2; i < k; i++)
{
    if ((tabl1[i].y != null) && (tabl[i].x != null))
    {
        double[] y2 = { 0, tabl1[i].y };
        double[] x2 = { tabl[i].x, 0 };
        dict.Add(i, new PointPairList(x2, y2));
    }
}

有了它,您可以通过这种方式轻松获取例如第四项:dict[4].

于 2013-01-13T21:36:32.077 回答