Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 652345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:15:45+00:00 2026-05-13T22:15:45+00:00

Using C# I was trying to develop the following two. The way I am

  • 0

Using C# I was trying to develop the following two. The way I am doing it may have some problem and need your kind advice. In addition, I dont know whether there is any existing method to do the same.

private static String HexConverter(System.Drawing.Color c)
{
    String rtn = String.Empty;
    try
    {
        rtn = "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
    }
    catch (Exception ex)
    {
        //doing nothing
    }

    return rtn;
}

private static String RGBConverter(System.Drawing.Color c)
{
    String rtn = String.Empty;
    try
    {
        rtn = "RGB(" + c.R.ToString() + "," + c.G.ToString() + "," + c.B.ToString() + ")";
    }
    catch (Exception ex)
    {
        //doing nothing
    }

    return rtn;
}

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:15:45+00:00Added an answer on May 13, 2026 at 10:15 pm

    I’m failing to see the problem here. The code looks good to me.

    The only thing I can think of is that the try/catch blocks are redundant — Color is a struct and R, G, and B are bytes, so c can’t be null and c.R.ToString(), c.G.ToString(), and c.B.ToString() can’t actually fail (the only way I can see them failing is with a NullReferenceException, and none of them can actually be null).

    You could clean the whole thing up using the following:

    private static String ToHex(System.Drawing.Color c)
        => $"#{c.R:X2}{c.G:X2}{c.B:X2}"
        
    private static String ToRGB(System.Drawing.Color c)
        => $"RGB({c.R},{c.G},{c.B})"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop an application using ADO.NET. I have two tables in
I'm trying to develop a site using Zend Framework, but i have a problem:
I am trying to develop an iphone application using sencha framework .I need to
I am trying to develop a mobile app using Sencha touch .I need to
Note: I'm using monotouch. Hello, I'm trying to develop the following UI: UIVIewController (root)
Using java I am trying to develop a method using recursion to analyze a
I'm trying to develop for Arduino using a Macbook Air. I purchased an Arduino
I am trying to develop a site using pinax. To index the models using
I'm trying to develop an app using XNA and for state management I'm using
I'm trying to develop a new webservice using JAX-WS and JAXB annotations. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.