I have below code which retrieves a list from a subfunction and returns it back to a main function. My problem is I cannot concatenate the result from the subfunc to the enumerable declared in mainfunc. Is there something I am missing?
private void MainFunc()
{
IEnumerable<CustomClass> keys = Enumerable.Empty<CustomClass>();
foreach (var item in items)
{
keys.Concat(SubFunc(item));
}
}
private IEnumerable<CustomClass> SubFunc (string y)
{
IEnumerable<CustomClass> list = GetList(y).ToList();
return list;
}
.Concat()
does not mutate the subject, but returns a new IEnumerable<T>
.
You're just throwing it away.
Fix your code with:
keys = keys.Concat(SubFunc(item))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With