-3
我嘗試將元素添加到double[,]
數組。但是它出現了一些問題。我必須在JSON中保存座標。它看起來像這樣:在double [,]數組中添加元素
{
"Polyline": [
{
"name": "Line1",
"towers": [
[13.32, 33.12],
[3.7, 565.5432],
[867.762, 653.1676],
...
]
]
}
}
這裏是代碼:
public double[,] GetTowersById(List<Towers> towers)
{
double[,] towersCoords = new double[towers.Count-1, towers.Count-1];
using (ZadiagDBEntities context = new ZadiagDBEntities())
{
//List<Towers> tower = new List<Towers>();
foreach (var item in towers)
{
int counter = 0;
var tower = context.Towers.First(t => t.ID == item.ID); // it is an object like Tower tower = new Tower(); with properties tower.Lat and tower.Long (their type is double)
object currentElem = new double[]{ Convert.ToDouble(tower.Lat), Convert.ToDouble(tower.Long) };
towersCoords.SetValue(currentElem, counter, counter);
counter++;
}
//tower = context.Towers.Where(t => t.ID == towers[i].ID).ToList();
}
錯誤消息:
Array is not single dimensional
「有些問題」? –
towerCoords是什麼類型的對象? – jdweng
信息太少... –