I need a help to understand this problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

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; } } } }

26th Feb 2021, 12:55 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
17 Answers
26th Feb 2021, 1:11 AM
visph
visph - avatar
+ 3
Yeah! I got it... you should also output "New post" (and not "New Post") inside of constructor... check my updated code ;)
26th Feb 2021, 1:39 AM
visph
visph - avatar
+ 1
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() { }
26th Feb 2021, 1:04 AM
visph
visph - avatar
+ 1
don't care, I have found it... I will try by by own ;)
26th Feb 2021, 1:27 AM
visph
visph - avatar
+ 1
this last exercice in part calsses and object i tutorial C#
26th Feb 2021, 1:28 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
+ 1
great it's is work
26th Feb 2021, 1:44 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
+ 1
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; } } } }
4th Mar 2021, 6:58 PM
Muhammad Arsalan
Muhammad Arsalan - avatar
0
yeah I try this but not work
26th Feb 2021, 1:07 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
0
youre code is work like my code nothing change bro
26th Feb 2021, 1:16 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
0
where are you trying to run it?
26th Feb 2021, 1:17 AM
visph
visph - avatar
0
in fact youre code and my code is true but with this exercice not work do you understand me?😅
26th Feb 2021, 1:19 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
0
no? could you share the link of the exercise?
26th Feb 2021, 1:24 AM
visph
visph - avatar
0
I don't find a way to share links but I can copy text of exercice
26th Feb 2021, 1:26 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
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!
26th Feb 2021, 1:26 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
0
Recall the value keyword for set accessor.
26th Feb 2021, 1:27 AM
Elmehdi Elmohammady
Elmehdi Elmohammady - avatar
0
It is OK, no error
27th Feb 2021, 9:34 PM
Abdullah Abdelhakeem
Abdullah Abdelhakeem - avatar
- 1
Ь б хьжюд, я и л
27th Feb 2021, 2:41 PM
MrSazerS
MrSazerS - avatar