1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 14:16:55 +02:00
CodeWars/5kyu/rgb_to_hex_conversion/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

16 lines
360 B
C#

public class Kata
{
public static int Constrain(int val, int min, int max) {
if (val < min) return min;
else if (val > max) return max;
else return val;
}
public static string Rgb(int r, int g, int b)
{
r = Constrain(r, 0, 255);
g = Constrain(g, 0, 255);
b = Constrain(b, 0, 255);
return $"{r,2:X2}{g,2:X2}{b,2:X2}";
}
}