相关疑难解决方法(0)

C#中多维数组和数组数组之间有什么区别?

C#中多维数组double[,]和数组数组之间有什么区别double[][]

如果有差异,每个人的最佳用途是什么?

c# jagged-arrays multidimensional-array

437
推荐指数
7
解决办法
13万
查看次数

使用C#从标准文本创建GeoJSON输出

我正在尝试创建类似于此处描述的GeoJSON格式的JSON输出:http: //geojson.org/geojson-spec.html

特别是,我从文本格式的数据源返回文本,并希望以下面的评论显示的格式将我的DTO转换为JSON.我遇到的主要问题是尝试创建没有属性名称的坐标数组[[...]].

码:

/*

                Geometry Text Format from database:  POLYGON ((319686.3666000003 7363726.7955, 319747.05190000031 7363778.9233, 319700.78849999979 7363832.7814, 319640.10329999961 7363780.6536, 319686.3666000003 7363726.7955))

                And we want format:
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [[
                        [319686.3666000003, 7363726.795],
                        [319747.0519000003, 7363778.9233],
                        [319700.78849999979, 7363832.7814],
                        [319640.10329999961, 7363780.6536],
                        [319686.3666000003, 7363726.795]
                    ]]
                }

                */


                // Strip out everything except the coordinates
                var coordRawText = myWkt.Replace("POLYGON ((", "");
                coordRawText = coordRawText.Replace("))", "");
                coordRawText = coordRawText.Replace(", ", ",");

                // Seperate coordinates to iterate through
                var coordsArray = coordRawText.Split(',');
                var coordsEnumerable …
Run Code Online (Sandbox Code Playgroud)

c# json dto geojson asp.net-web-api2

5
推荐指数
1
解决办法
4134
查看次数

c#linq从linq返回一个多维数组

我想返回一个多维数组来保存在一个会话中,但不知道如何从linq返回它:

public string[] GetCountryAndManufacturerForUser(int userId)
{

        var array = (from xx in _er.UserRoles
                     join xy in _er.Countries on xx.CountryId equals xy.Id
                     join xz in _er.Manufacturers on xx.ManufacturerId equals xz.Id
                     where xx.UserId == userId
                     select new { xy.Name, xz.Description }).ToArray();   

    return??
}
Run Code Online (Sandbox Code Playgroud)

我知道我在这里做错了,不知道是什么.

编辑:

需要返回以下字段 - xy.Name,xz.Description

喜欢:

 { "1", "aaa" },
   { "2", "bbb" }
Run Code Online (Sandbox Code Playgroud)

编辑:

我已经尝试了下面的例子,他们还没有到达我需要的地方 - 我认为以下内容应该有效:

 /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string[,] GetCountryAndManufacturerForUser(int userId)
    {

        var array = (from xx in …
Run Code Online (Sandbox Code Playgroud)

c# linq arrays multidimensional-array

4
推荐指数
1
解决办法
1万
查看次数

将List <int []>转换为int [,]

如何转换List<int[]>int[,] 列表中所有数组的位置int[2]

我尝试着:

List<int[]> list = new List<int[]>();
list.Add(new int[2] { 3, 4 });
int[,] arr = list.ToArray();
Run Code Online (Sandbox Code Playgroud)

c#

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