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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:42:15+00:00 2026-06-08T07:42:15+00:00

How does CLR determine which Color zero should be converted to? internal static class

  • 0

How does CLR determine which Color zero should be converted to?

internal static class Test
{
    private static void Main()
    {
        Console.WriteLine((Color)0);
    }

    private enum Color
    {
        Red,
        Green = Red
    }
}

Using this Color’s definition “Red” will be outputted.

If we use other definitions, results are really very interesting.

private enum Color
{
    Red,
    Green = Red,
    Blue = Red,
    Yellow = Red
}

The output is “Green”.

Another definition:

private enum Color
{
    Red,
    Green = Red,
    Blue,
    Yellow  = Red
}

The output is “Yellow”.

  • 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-06-08T07:42:16+00:00Added an answer on June 8, 2026 at 7:42 am

    It just returns a Color value with an underlying value of 0. That’s the same value as Color.Red and Color.Green.

    Fundamentally, your enum is broken in that Red and Green are the same value. You can’t distinguish between them at all.

    Color red = Color.Red;
    Color green = Color.Green;
    Console.WriteLine(red == green); // True
    Console.WriteLine(red.ToString() == green.ToString()); // True
    

    I don’t know if there are any guarantees around whether ToString returns “Red” or “Green” – but if you get to the situation where that’s relevant, you should have described your enum differently.

    EDIT: From the documentation:

    If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member’s name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, Shade.Gray and Shade.Grey, that have the same underlying value.

    …

    The following method call attempts to retrieve the name of a member of the Shade enumeration whose underlying value is 1. The method can return either “Gray” or “Grey”, and your code should not make any assumptions about which string will be returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public class Test { public static void Main() {
[TestFixture] public class ExpandoToMessageConverterTests { /// <summary> /// CanConvertEvent /// </summary> [Test] public void
I've read http://dbaspot.com/sqlserver-programming/463313-32-bit-clr-procedure-64-bit-sql-server.html Does that mean it's not possible to run a 32 bits
Does .net CLR typecast the objects to the ones mentioned in the collection declaration?
Does the .NET CLR runtime know how to optimize/inline simple property getters at runtime?
How does the .NET CLR handle multiple instances of the same program running simultaneously?
Out of curiosity: how does the CLR dispatch virtual method calls to interface members
The CLR does not support covariant return types or full variance (i. e. applied
For example when you introduce an static class in your source code, csc compiler
When multiple threads request a lock on the same object, does the CLR guarantee

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.