I have the below
string currency = string.Empty;
Regex r = new Regex(@"~(\w*[a-zA-Z0-9$£~%]+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
for (Match m = r.Match(expression); m.Success; m = m.NextMatch())
{
currency = (m.Groups[1].Value);
break;
}
return currency;
The intension is that, after the first match in the loop it should break.
The warning messge(Unreachable code) is happening m = m.NextMatch() of the loop.
How to overcome this?
Thanks
Your code is currently broken, basically. You’re really never going to execute
m = m.NextMatch(), so why have it?I think you want:
Personally I think this is rather clearer, in terms of what the final version of “currency” is.