Enum.ToString() is returning default value instead of specified value

Enum.ToString() is returning default value instead of specified value

I am trying to write a game, and I am using an enum to store colors of paint. The enum keeps returning the default value instead of the value of the field. Is there a way to prevent this?

I am trying to write a game, and I am using an enum to store colors of paint. The enum keeps returning the default value instead of the value of the field. Is there a way to prevent this?

This is a C# .NET Forms application, for .NET Framework 4.6.1.

Here is my code:

public enum PaintColor
{
    Red,
    Orange,
    Yellow,
    Green,
    Blue
}
class Form1 : Form
{

private void Form1_Load(Object sender, EventArgs e)
{
    PaintBucket orange = new PaintBucket()
    {
        Color = PaintColor.Orange,
        Amount = 22
    };
    Label OrangeContent = new Label
    {
        Text = (orange.ToString()),
        Width = 100,
        Height = 20,
        Top = 500,
        Left = 500
    };
}

}

and then the overriden ToString method inside the PaintBucket class:

public override string ToString()
{
    return (this.Color.ToString() + ", " + this.Amount.ToString());
}

As you can see above, the field orange contains an orange PaintBucket. The label OrangeContent, contains orange.ToString. But it shows up as Red, 0 instead of Orange, 22. Red is the default value of the enum, and 0 is the default value for the integer. Is there a way to return the value of the fields instead of the default?

c-sharp .net

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C. C++. C#. 차이점 알려드림. 5분 순삭. Explain C.C++.C#. Like I'm Five

C. C++. C#. 차이점 알려드림. 5분 순삭. Explain C.C++.C#. Like I'm Five. 아시죠? C는 C++.C# 줄인말이 아니라는거?

Learn how to perform CRUD operations using C Sharp

QuickStart: CRUD Operations in C Sharp. Learn how to perform CRUD operations using C Sharp for MongoDB databases.

How to creating a Fluent API class in C#.NET

In this article we will look at creating a Fluent API class in C#.NET. In a Fluent API, we can link together different functionality to get a particular result. We see this used many times in Entity Framework Core and when manipulating List<T> type of items using lambda expressions.

Pixel Color Bot in C#, Visual Studio, .NET and WPF

Create a Pixel Color Bot in C# Visual Studio by using the .NET framework and WPF. This C# tutorial guides you through the development process of creating a pixel bot.

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.