+ 2

What am I doing wrong? C# Practice 38.3

Hi I'm having some trouble with this problem: class Program { static void Main(string[] args) { string name = Console.ReadLine(); string phoneNumber = Console.ReadLine(); User user1 = new User(name, phoneNumber); user1.ShowDetails(); } } class User { private string userName; private string phoneNumber; //complete the constructor public User() { Console.WriteLine("Profile is created"); } public void ShowDetails() { Console.WriteLine("Name: " + userName); Console.WriteLine("Phone number: " + phoneNumber); } } } I've tried all kinds of things, adding strings into the User constructor, adding public strings with get and set, using ref on the strings, etc. the best I've been able to do is output: " Profile is created Name: Phone number: " Any tips or examples would be greatly appreciated!

24th Feb 2022, 9:58 PM
Darice Keeling
1 Odpowiedź
+ 4
Your constructor doesn't really do anything useful. You are passing parameters to the constructor, but you are not setting them on the attributes. Ending up with two empty strings. Do this public User(string userName, string phoneNumber) { this.userName = userName; this.phoneNumber = phoneNumber; // the printout you want }
24th Feb 2022, 10:52 PM
Mustafa A
Mustafa A - avatar