I was reading C# 7.0 changelog and ran into an example that shows new tuples syntax.
private static (int Max, int Min) Range(IEnumerable<int> numbers)
{
int min = int.MaxValue;
int max = int.MinValue;
foreach(var n in numbers)
{
min = (n < min) ? n : min;
max = (n > max) ? n : max;
}
return (max, min);
}
And I got curious if the compiler optimizes lines like min = (n < min) ? n : min;
cause min = min
operation seems a bit useless. I compiled the code (in release mode) and opened it in ILDASM and saw that min = min
assignment was still there.
Is it a tough question for the compiler to skip the assignment? Or maybe it's because of some multi-threading issue?
ref
parameters]( sharplab.io/…) – Necrose