How to convert RGB to hex in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        int r = 80;
        int g = 125;
        int b = 210;

        string hex = string.Format("#{0:X2}{1:X2}{2:X2}", r, g, b); 
        
        Console.Write(hex);
    }
}
 
 
 
/*
run:
 
#507DD2
 
*/

 



answered Dec 28, 2021 by avibootz

Related questions

1 answer 164 views
164 views asked Mar 6, 2025 by avibootz
1 answer 226 views
2 answers 248 views
2 answers 219 views
2 answers 248 views
2 answers 231 views
231 views asked Mar 6, 2025 by avibootz
2 answers 242 views
...