I'm using C# 8 with nullable
enabled and now I'm having a problem with my regex loop:
public static async Task<IEnumerable<WorkerDto>?> GetOwnersAsync(LampContext context, string? ownerString)
{
if (string.IsNullOrWhiteSpace(ownerString))
return null;
var wwids = new List<int>();
var matches = Regex.Matches(ownerString, @"\d+");
foreach (Match match in matches)
wwids.Add(int.Parse(match.Value));
It's saying I have a possible null reference assignment to the match
iteration variable, and I'm not sure why it would say that, or how to get around it. The documentation for Matches says it'll return an empty collection, not null.
How am I supposed to write that code now?