我試圖實現的是將字符串拆分爲多個地址,如「NL,VENLO,5928PN」getLocation將返回一個「POINT(xy)」字符串值。在foreach中創建對象以推送到C#中的數組#
This Works。接下來,我需要爲每個位置創建一個WayPointDesc對象。並且每個這些對象都必須推入WayPointDesc []。我嘗試了各種方法,但到目前爲止我找不到可行的方法。我最後的手段是硬編碼最大數量的航點,但我寧願避免這樣的事情。
不幸的是,使用列表不是一種選擇...我想。
這是函數:
/* tour()
* Input: string route
* Output: string[] [0] DISTANCE [1] TIME [2] MAP
* Edited 21/12/12 - Davide Nguyen
*/
public string[] tour(string route)
{
// EXAMPLE INPUT FROM QUERY
route = "NL,HELMOND,5709EM+NL,BREDA,8249EN+NL,VENLO,5928PN";
string[] waypoints = route.Split('+');
// Do something completly incomprehensible
foreach (string point in waypoints)
{
xRoute.WaypointDesc wpdStart = new xRoute.WaypointDesc();
wpdStart.wrappedCoords = new xRoute.Point[] { new xRoute.Point() };
wpdStart.wrappedCoords[0].wkt = getLocation(point);
}
// Put the strange result in here somehow
xRoute.WaypointDesc[] waypointDesc = new xRoute.WaypointDesc[] { wpdStart };
// Calculate the route information
xRoute.Route route = calculateRoute(waypointDesc);
// Generate the map, travel distance and travel time using the route information
string[] result = createMap(route);
// Return the result
return result;
//WEEKEND?
}
爲什麼你不能用一個列表,然後在完成時調用ToArray的就可以了? – mletterle
是不是wpd超出了你目前實現的範圍? – 2012-12-21 14:26:20
@mletterle謝謝。我剛剛做到了。 – Perfection