Last task in exercise here want you to initialise hobbies array with length of zero in the constructor to prevent exception when ViewProfile is called and hobbies have not been set.
“If you call
ViewProfile() before calling
SetHobbies() , you’ll get an error because the
hobbies field isn’t set to any value. Fix the class so that you can call
ViewProfile() without adding hobbies.”
In the constructor of ViewProfile, I’ve tried to initialise hobbies array with length of zero with no luck, can anyone help with what I doing incorrectly?
As is is below I get an error saying that value for hobbies must be a compile time constant.
How does one initialise array with length of 0 in ViewProfile constructor?
private string name;
private int age;
private string city;
private string country;
private string pronouns;
private string hobbies;
public Profile(string name,int age,string city,string country,string pronouns = "they/them",string hobbies = new string)
this.name = name;
this.age = age;
this.city = city;
this.country = country;
this.pronouns = pronouns;
this.hobbies = hobbies;