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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:53:50+00:00 2026-06-12T17:53:50+00:00

I am currently learning to work with abstract classes and virtual . I created

  • 0

I am currently learning to work with abstract classes and virtual. I created a simple form that generates the names of animals, color, and the sound they make. Everything seems to work right except for color display property. The results are being displayed in a multiline textBox. Is there a way to display the result with only the color name instead of this format Color [DarkGray]?

Result when button clicked:

Betty is a Color [DarkGray] horse with four legs and runs very fast that goes neigh! neigh!!

The desired result:

Betty is a Dark Gray horse with four legs and runs very fast that goes neigh! neigh!!

CODE

namespace farm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public abstract class Animal
        {
            protected string the_name;
            protected string the_type;
            protected Color the_color;
            protected string features;

            public virtual string speaks()
            {
                return "";
            }

            public override string ToString()
            {
                string s = the_name + " is a " + the_color + " " + the_type + " with " + features + " that goes " + speaks();
                return s;
            }
        }

public class Horse : Animal
        {
            public Horse(string new_name, Color new_color)
            {
                the_name = new_name;
                the_color = new_color;
                the_type = "horse";
                features = "four legs and runs very fast";

            }

            public override string speaks()
            {
                return "neigh! neigh!!";
            }

        }

 private void button1_Click(object sender, EventArgs e)
        {

            Horse horse1 = new Horse("Topaz", Color.DarkGray);
            textBox1.AppendText(horse1.ToString());
        }
    }
}
  • 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-12T17:53:51+00:00Added an answer on June 12, 2026 at 5:53 pm

    Yes, in your ToString method, use:

    the_color.Name
    

    Or better still, if you want to have a string with whitespace in where the string contains upper case characters, e.g. DarkGray => Dark Gray, you could define an extension like this

    public static class ColorExtensions
    {
        public static string GetColorString(this Color color)
        {
            StringBuilder sb = new StringBuilder();
            foreach(char c in color.Name.ToCharArray())
            {
                if (char.IsUpper(c))
                    sb.Append(' ');
    
                sb.Append(c);
            }
    
            return sb.ToString();
        }
    }
    

    and call it like this

    the_color.GetColorString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently learning how eclipse plugins work. I want to get a table into
I am currently learning how to work with the stopwatch attribute in C#. I
I'm currently learning objective c and I'm trying to write some simple apps to
I am currently learning how to work with the registry using c++. I have
I am currently learning template variables and trying to understand how they work and
Currently I'm learning about neural networks and I'm trying to create an application that
I am in the process of learning Backbone.js. I currently assume that if one
I am using MongoDB in our project and I'm currently learning how things work.
I'm currently learning Python, and I have to work on a Python 2.7 project.
I am currently learning how to work in Objective-C / Cocoa Touch and 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.