c# - Array-List not contains -
i have list 2 attributs/objects. first int-array 2 ids.
i want add new object list, if value 12 and 21 (only in combination) not exist in ids-array of hole list. //if 1 single id found okay - combination of both ids needs jump else-case. :)
*12 , 21 vars later, no static values
i don't know why, isn't working...
if (id != destination.id && !(thisdistances.exists(x => x.ids.contains(12)) && thisdistances.exists(x => x.ids.contains(21)))) { ... }
public class distancedata { public int[] ids; public int distance; } protected void makedistances(int id, double geolat, double geolon, int limit = 100) { int = 0; list<distancedata> thisdistances = new list<distancedata>(); foreach (var destination in destinations) { if (id != destination.id && !(thisdistances.exists(x => x.ids.contains(12)) && thisdistances.exists(x => x.ids.contains(21)))) { thisdistances.add(new distancedata() { ids = new int[2] { id, destination.id }, distance = (int)math.round(6378388 * math.acos(math.sin(geolat) * math.sin(destination.geolat) + math.cos(geolat) * math.cos(destination.geolat) * math.cos(destination.geolon - geolon)), 0, midpointrounding.awayfromzero) }); if (++i > 10) break; } } thisdistances = thisdistances.orderby(x => x.distance).take(limit).tolist(); foreach (var thisdistance in thisdistances) { response.write("<i><b>" + thisdistance.distance + "</b> (" + thisdistance.ids[0] + "," + thisdistance.ids[1] + ")</i><br />"); } }
how can check, both ids not in ids-array of objectlist?
try one:
foreach (var destination in destinations) { if (id != destination.id && (thisdistances.exists(x => x.ids.contains(12) && x.ids.contains(21)) == false)) { thisdistances.add(new distancedata() { ids = new int[2] { id, destination.id }, distance = (int)math.round(6378388 * math.acos(math.sin(geolat) * math.sin(destination.geolat) + math.cos(geolat) * math.cos(destination.geolat) * math.cos(destination.geolon - geolon)), 0, midpointrounding.awayfromzero) }); if (++i > 10) break; } }
Comments
Post a Comment