Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to convert from HEX color to RGB in C#

1 Answer

0 votes
using System;
using System.Globalization;

public class HexToRgbConverter
{
    public static (int R, int G, int B) HexToRgb(string hex) {
        // Remove the '#' character if present
        hex = hex.TrimStart('#');

        // Parse the hex string into an integer
        int hexValue = int.Parse(hex, NumberStyles.HexNumber);

        // Extract the RGB components
        int r = (hexValue >> 16) & 0xFF;
        int g = (hexValue >> 8) & 0xFF;
        int b = hexValue & 0xFF;

        return (r, g, b);
    }

    public static void Main()
    {
        string hexColor = "#FF5705";
        
        var (r, g, b) = HexToRgb(hexColor);
        
        Console.WriteLine($"RGB: ({r}, {g}, {b})");
    }
}


 
/*
run:

RGB: (255, 87, 5)
     
*/

 



answered Mar 6, 2025 by avibootz

Related questions

1 answer 44 views
1 answer 103 views
2 answers 97 views
2 answers 71 views
2 answers 78 views
2 answers 84 views
2 answers 95 views
...