static int[] initializLineStations(int lineId, int numOfLS = 10) { List <DO.LineStation> stationTemp = new List <DO.LineStation>(); var first = new DO.LineStation() { LineId = lineId, Station = RandomValues.getStation(stationTemp), LineStationIndex = 0, PrevStation = 0, IsDeleted = false }; var area = StationsList.Find(s => s.Code == first.Station).Area; stationTemp.Add(first); for (int i = 1; i < numOfLS; i++) { stationTemp.Add(new DO.LineStation() { LineId = lineId, Station = RandomValues.getStation(stationTemp, area), LineStationIndex = i, PrevStation = stationTemp.ElementAt(i - 1).Station, IsDeleted = false }); } foreach (var ls in stationTemp) { if (ls.LineStationIndex != stationTemp.Count - 1) { ls.NextStation = stationTemp.ElementAt(ls.LineStationIndex + 1).Station; } else { ls.NextStation = -1; // last station mark in -1 } } LineStationsList.AddRange(stationTemp); return(new int[] { stationTemp.ElementAt(0).Station, stationTemp.ElementAt(stationTemp.Count - 1).Station }); }