I have the following code:
contact.AddressList.ForEach(async (address) => { //...... returnValues = await _apiDataService.CallEndPointAPIAsync( Contact, token, "ContactApiEndpoint"); if (returnValues.Response.StatusCode != System.Net.HttpStatusCode.OK) { //jump out of here } }); If for any reason the call, doesn't return ok, I want to jump of here, I thought I'd get away with break; but that's not allowed at this point.
contact.AddressList.ForEachis not awaited. (and can not be)ForEachextension, it is really pointless. It doesn't make your code more readable, it's slower since it needs to create a lambda, there are side effects such as closures, and arguably goes against Linq principles (i.e. it's not a query, you can mutate the data)asynccode anywayForEachisn't a LINQ extension method, it's an own method ofList<T>. Still valid comment though, and I agree.fororforeachloop. Execute them in parallel? Then what happens to the other requests, when one fails?