C# ASP.NET MVC Basics Modeling and Presenting Data Creating a Data Model

ALBERT QERIMI
ALBERT QERIMI
49,869 Points

output value in parentheses in C#

stuck in this challange anybody help how to output parentheses in C#

Bummer! For the property's return value, are you returning the 'Title' property value followed by the 'Publisher' property value in parentheses (i.e. "Super Mario 64 (Nintendo)")?

VideoGame.cs
namespace Treehouse.Models

{

   public class VideoGame{
    public int Id {get ; set ;}
     public string Title {get ; set;}
     public string Description {get ; set; }
       public string []Characters {get ; set;}
       public string Publisher {get ; set;}

   public string DisplayText {

    get{
            return  ////stuck here

    }
   }

   }
}

4 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Albert,

To return a concatenated string you'll need to do something like this.

public string DisplayText
{
    get
    {
        return PropertyA + " (" + PropertyB + ")";
    }
}

I hope this helps.

Steven Parker
Steven Parker
171,137 Points

You're so close! You only need to combine the strings along with some parentheses (and a space). There's a few ways to do that. The most basic way would be with string concatenation:

                return Title + " (" + Publisher + ")";

On the other end of the scale would be a single-line expression-bodied computed property with string interpolation:

        public string DisplayText => $"{Title} ({Publisher})"; 

Either will pass the challenge, but the latter is probably a bit beyond the scope of the course. :smile:

ALBERT QERIMI
ALBERT QERIMI
49,869 Points

Thanks you Guys for help

The problem on this challenge is that in the question, the line breaks so that one cannot tell if there is a space after the Title or not. So, not adding the space-- " (" -- does not pass the test.