using System;
namespace ConsoleApp1
{
public static class RGBClass
{
static char[] SixChar = new char[6] { 'A', 'B', 'C', 'D', 'E', 'F' };
static public string RGB(int r,int g,int b)
{
string result = "";
int CurrentNum = 0;
int[] rgb = new int[3] { r, g, b };
foreach (int element in rgb)
{
CurrentNum = element;
if (element != 0)
{
if (element > 16)
{
while (CurrentNum/16 != 0) // Цикл выполняется только 1 раз, хотя после первого раза значения равно 15
{
switch (element % 16)
{
case 10:
result += SixChar[0];
break;
case 11:
result += SixChar[1];
break;
case 12:
result += SixChar[2];
break;
case 13:
result += SixChar[3];
break;
case 14:
result += SixChar[4];
break;
case 15:
result += SixChar[5];
break;
default:
result += element % 16;
break;
}
CurrentNum /= 16;
}
}
}
else
{
result += "00";
}
}
return result;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(RGBClass.RGB(0,255,0));
Console.Read();
}
}
}
using System;
namespace App
{
class Program
{
static void Main(string[] args)
{
var color = new RgbColor(0, 255, 0);
Console.WriteLine(color.ToString());
}
}
public readonly struct RgbColor
{
private readonly byte red;
private readonly byte green;
private readonly byte blue;
public RgbColor(int red, int green, int blue)
{
if (red < 0 || green < 0 || blue < 0 || red > 255 || green > 255 || blue > 255)
throw new ArgumentOutOfRangeException();
this.red = (byte) red;
this.green = (byte) green;
this.blue = (byte) blue;
}
public int Red => red;
public int Green => green;
public int Blue => blue;
public override string ToString() => $"{red:X2}{green:X2}{blue:X2}";
}
}