在 C++ 中如何在 return 语句中循环数组
in c++ how to loop an array in return statement
public async Task < IActionResult > Events(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest httpRequest,
ILogger log) {
ValidateResponse res = eventService.ValidateSchema();
if (res.Valid == false && res.Errors != null) {
string[] messages = new string[100];
int k = 0;
for (int i = 0; i < res.Errors.Count; i++) {
string value = res.Errors[i].ToString();
if (value.StartsWith("Invalid type")) {
messages[k++] = value.Substring(10);
continue;
}
}
return new OkObjectResult($ "No of events posted {cloudEvents.Count} and errors :{messages[k]}");
}
但消息中的值未 returned。我知道它是一个数组。但是无法找出在return所有数组值中循环一次的方法。
一个选项是将 messages
数组连接到一个字符串:
return new OkObjectResult($"No of events posted {cloudEvents.Count} and errors:{String.join(\",\", messages}");
public async Task < IActionResult > Events(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest httpRequest,
ILogger log) {
ValidateResponse res = eventService.ValidateSchema();
if (res.Valid == false && res.Errors != null) {
string[] messages = new string[100];
int k = 0;
for (int i = 0; i < res.Errors.Count; i++) {
string value = res.Errors[i].ToString();
if (value.StartsWith("Invalid type")) {
messages[k++] = value.Substring(10);
continue;
}
}
return new OkObjectResult($ "No of events posted {cloudEvents.Count} and errors :{messages[k]}");
}
但消息中的值未 returned。我知道它是一个数组。但是无法找出在return所有数组值中循环一次的方法。
一个选项是将 messages
数组连接到一个字符串:
return new OkObjectResult($"No of events posted {cloudEvents.Count} and errors:{String.join(\",\", messages}");