The fastest way I know of is to use
max(min(a, b), min(max(a, b), c))
I'm trusting that C# has optimisations for min
and max
taking two arguments. This will be quicker than taking if
statements due to branching.
There are other tricks: you can implement min and max using XOR and < but I doubt that has any benefits on modern architectures.