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 6664985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:40:28+00:00 2026-05-26T02:40:28+00:00

I could be looking at Enums in the wrong way but want to make

  • 0

I could be looking at Enums in the wrong way but want to make sure I have the right theory in how to use them.

Say we have an enum called Colour.

enum Colour { Red, Green, Blue };

Red Green and Blue are represented by there 0-255 values.
I’m trying to initialize this enum inside a class shape and I’m not really sure how to go about it.

public class Shape
{

    Colour colour;

    public Shape(Colour c)
    {
         //Some attempts at initialization.


         //Treating It like an object
         this.colour = 
            c{
                255,255,255
            };

         //Again
         this.colour.Red = c.Red
         this.colour.Blue = c.Blue
         this.colour.Green = c.Green

         Colour.red = c.red?


         }
    }
}

I’m probably way off in terms of how I’m thinking about enums. Can anyone give me some pointers?

  • 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-26T02:40:29+00:00Added an answer on May 26, 2026 at 2:40 am

    In this case, you might want Colour to be struct instead of an enum. In C#, enums are single-valued constructs, but you have three values (red, green, and blue). Here’s what I might do instead:

    public struct Colour 
    {
        private byte red;
        private byte green;
        private byte blue;
    
        public Colour(byte r, byte g, byte b) 
        {
            this.red = r;
            this.green = g;
            this.blue = b;
        }
    }
    
    public class Shape
    {
        public Colour Colour { get; private set; }
    
        public Shape(Colour c)
        {
            this.Colour = c;
        }
    }
    

    And then when you’re creating your shape objects:

    var shape = new Shape(new Colour(203, 211, 48));
    

    EDIT: As Chris pointed out in the comments, you could simply use the System.Drawing.Color struct provided by the framework. The example above would be simplified to:

    using System.Drawing;
    
    public class Shape
    {
        public Color Colour { get; private set; }
    
        public Shape(Color c)
        {
            this.Colour = c;
        }
    }
    
    var shape = new Shape(Color.FromArgb(203, 211, 48));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking everywhere but could not find a tutorial for this. I
I'm sure this would have been asked before, but I'm very confused! Say I
I'm looking for a program or library that I could use for experimenting with
I'm looking for some type of profiling utility I could use where I can
I have the folowing question: What is the prefered way to use the status
I am looking for ways that someone could maliciously pause a Flash movie -
I'm looking for a library that could be used to manipulate audio files. Essentially
I am looking for an algorithm that could find the two most distant elements
I'm looking for a good address-parser that could parser any free texts and generate
I am looking out for an eclipse plug-in that could be used to detect

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.