Giving a default value of an array of length 0 withing Constructor?!

So can anyone help me with Giving array “hobbies” a default value of an array of length 0 withing Constructor?
I do not understand what to do and I have tried everything, including googling. But no success, just different errors all the time. The unstuck video from CodeAcademy unfortunatly skips exactly this step as it is optional.

Assignment “The Object of Your Affection”

Thank you in advance :slight_smile:

using System; namespace DatingProfile { class Profile { // Fields private string name; private int age; private string city ; private string country; private string pronouns; private string[] hobbies; // Constructor public Profile( string name, int age, string city = "n/a", string country = "n/a", string pronouns = "they/them", string[] hobbies = new string[]) // HERE !!!!!!!!!!!!!!!!! { this.name = name; this.age = age; this.city = city; this.country = country; this.pronouns = pronouns; this.hobbies = hobbies; } // Properties // Methods public string ViewProfile() { string listHobbies = ""; if (this.hobbies.Length > 0) { foreach (string hob in hobbies) { listHobbies = listHobbies + "\n" + hob; } } return $"{name} {age} {city} {country} {pronouns} {listHobbies}"; } public void SetHobbies(string[] hobbies) { this.hobbies = hobbies; } } }

Hi,
You’re not going to be passing hobbies into the constructor as a parameter, so you don’t actually want line 21 (the one you’ve highlighted).

Instead it’s line 28 you want to be changing, within the constructor itself, to create your array;

this.hobbies = new string[0];

Hope this helps

1 Like

Yeah, thanks! It did solve the error!