简体   繁体   English

C#-锯齿数组

[英]C# - Array of Jagged Array

How to initialize and allocate array of jagged array? 如何初始化和分配锯齿状数组的数组? I am trying to create Geojson Polygon coordinates structure (with no holes) like the example geojson below using c# objects. 我正在尝试使用c#对象创建类似于下面的示例geojson的Geojson多边形坐标结构(无孔)。 My code able to generate the json which using jagged array and missing some bracket next to "coordinates": , but want that json like the example geojson, which can be possible using array of jagged array. 我的代码能够使用锯齿形数组生成json,并且缺少“ coordinates”旁边的括号:,但想要像示例geojson这样的json,可以使用锯齿形数组来实现。 Code example for array of jagged array would be appreciated. 锯齿状阵列的代码示例将不胜感激。

My code generated 我的代码生成

{ "type": "Polygon",
        "coordinates": 
          [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]

    }

Example Geojson Polygon 示例Geojson多边形

{ "type": "Polygon",
    "coordinates": [
      [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
      ]
}

Thanks. 谢谢。

Array of jagged arrays: 锯齿状数组:

double[][][] coordinates = 
            {
                new double[][]
                    {
                        new double[] {1, 3, 5, 7, 9},
                        new double[] {0, 2, 4, 6},
                        new double[] {11, 22}
                    }
            };

But, in my opinion, your first code sample seems to do the job. 但是,在我看来,您的第一个代码示例似乎可以完成任务。 Are you sure you need this? 您确定需要这个吗?

Actually, why not an array of GeoPoint , where a GeoPoint holds two double s and is mapped to a json array when serialized? 实际上,为什么不对一个GeoPoint数组进行序列化,在该数组中,一个GeoPoint拥有两个double并映射到json数组?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM