Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hallo...
I'm working with some complex coding. But I'm stuck at a very simple if statement:
string hotelNodeString = ""; foreach(var season in Model.Children.Where("Visible")) { hotelNodeString = hotelNodeString + season.seasonHotels; if(!season.IsLast()) { hotelNodeString = hotelNodeString + ","; } } string[] accommodationHotels = hotelNodeString.Split(','); string shipNodeString = ""; foreach(var season in Model.Children.Where("Visible")) { if(season.HasValue("seasonShips")) { shipNodeString = shipNodeString + season.seasonShips; if(!season.IsLast()) { shipNodeString = shipNodeString + ","; } } } string[] accommodationShips = shipNodeString.Split(','); List<string> accommodations = new List<string>(); foreach(string st in accommodationShips) { if (!accommodations.Contains(st)) { accommodations.Add(st); } } foreach(string st in accommodationHotels) { if (!accommodations.Contains(st)) { accommodations.Add(st); } }
For some reason the first foreach loop output a comma.
I need to check if the seasonHotels has a value. If not the loop shoudn't add anything.
I have tried to do this:
foreach(var season in Model.Children.Where("Visible")) { if(season.HasValue("seasonHotel")) { hotelNodeString = hotelNodeString + season.seasonHotels; if(!season.IsLast()) { hotelNodeString = hotelNodeString + ","; } } }
But it is the same result. All ideas is appreciated.
Oh well... I have fixed it for now:
string accommodationNodeString = ""; foreach(var season in Model.Children.Where("Visible")) { if(season.seasonHotels != "") { accommodationNodeString = accommodationNodeString + season.seasonHotels; } if(season.seasonShips != "") { accommodationNodeString = accommodationNodeString + season.seasonShips; } if(!season.IsLast()) { accommodationNodeString = accommodationNodeString + ","; } } string[] accommodationIDs = accommodationNodeString.Split(','); List<string> accommodations = new List<string>(); foreach(string st in accommodationIDs) { if (!accommodations.Contains(st)) { accommodations.Add(st); } }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Loop only if this has value - not working as expected
Hallo...
I'm working with some complex coding. But I'm stuck at a very simple if statement:
For some reason the first foreach loop output a comma.
I need to check if the seasonHotels has a value. If not the loop shoudn't add anything.
I have tried to do this:
But it is the same result. All ideas is appreciated.
Oh well... I have fixed it for now:
is working on a reply...