Is there a way to enforce never divide (/
) two int
in C# at compile-time/VS/editorconfig/etc?
e.g.
var a = 1;
var b = 2;
var c = a / b; // NO!
var d = (double)a / b; // OK
Thanks!
Context: I am working on a legacy code and it was dividing two int
values that rounded towards 0
. I suspect there are other places that the same scenario exists. Instead of enforcing, I think it will still be very beneficial to analyze the code to show all occurrences of division of int
and proactively fix the issue before it happens again.