I need a help to understand this problem | SoloLearn: Learn to code for FREE!

+1

I need a help to understand this problem

Social Network You are making a social network application and want to add post creation functionality. As a user creates a post, the text "New post" should be automatically outputted so that then the user can add the text he/she wants to share. The program you are given declares a Post class with a text private field, and the ShowPost() method which outputs the content. Complete the class with - a constructor, which outputs "New post" as called, - Text property, which will allow you to get and set the value of the text field. Once you have made the changes to the program so that it works correctly, then in main, the program will take the text of the post from the user, create a post object, assign the taken value to the text field and output it. Sample Input Hello! Sample Output New post Hello! Recall the value keyword for set accessor. My code using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string postText = Console.ReadLine(); Post post = new Post(); post.Text = postText; post.ShowPost(); } } class Post { private string text; //write a constructor here Post(){ } Post(string text){ this.text=this.text; } public void ShowPost() { Console.WriteLine("New Post"); Console.WriteLine(text); } //write a property for member text public string Text { get { return text; } set { text = value; } } } }

c#

2/26/2021 12:55:00 AM

Elmehdi Elmohammady

17 Answers

New Answer

+3

yes it works: try it... https://code.sololearn.com/ciMcLLJm2yBU/?ref=app

+3

you're declaring twice Post() method: delete the second one (leave the empty one) as it's not intented to initialize text property inside constructor... you should also provide an access level of 'public' of this constructor: public Post() { }

+3

Yeah! I got it... you should also output "New post" (and not "New Post") inside of constructor... check my updated code ;)

+1

don't care, I have found it... I will try by by own ;)

+1

this last exercice in part calsses and object i tutorial C#

+1

great it's is work

0

yeah I try this but not work

0

youre code is work like my code nothing change bro

0

where are you trying to run it?

0

in fact youre code and my code is true but with this exercice not work do you understand me?😅

0

no? could you share the link of the exercise?

0

I don't find a way to share links but I can copy text of exercice

0

You are making a social network application and want to add post creation functionality. As a user creates a post, the text "New post" should be automatically outputted so that then the user can add the text he/she wants to share. The program you are given declares a Post class with a text private field, and the ShowPost() method which outputs the content. Complete the class with - a constructor, which outputs "New post" as called, - Text property, which will allow you to get and set the value of the text field. Once you have made the changes to the program so that it works correctly, then in main, the program will take the text of the post from the user, create a post object, assign the taken value to the text field and output it. Sample Input Hello! Sample Output New post Hello!

0

Recall the value keyword for set accessor.

0

It is OK, no error

0

its working for me. using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string postText = Console.ReadLine(); Post post = new Post(); post.Text = postText; post.ShowPost(); } } class Post { private string text; //write a constructor here public Post(){ Console.WriteLine("New post"); } public void ShowPost() { Console.WriteLine(text); } //write a property for member text public string Text { get { return text; } set { text = value; } } } }

-1

Ь б хьжюд, я и л