The Object of Your Affection Project

Does anyone know how to do step 10 of the project? I don’t understand how I can loop through the hobbies array and add each hobby item to the string. Thank you in advance!

1 Like

If you have a string already for the rest of the bio called bio for example, you could create a new string bioHobbies, use a foreach() to iterate through this.hobbies adding each hobby to the bioHobbies string, and then append it to the end of the bio prior to returning bio.

Something like:

      string bioHobbies = "";
      foreach(string hobby in this.hobbies)
      {
        bioHobbies += hobby + ", ";
      }
      bio += $"Hobbies: {bioHobbies}";
2 Likes

Had the same question and thanks for this, worked well.
Anyways have problem with the next step (11) which is: Above where you print sam ‘s profile information out, add some hobbies to sam
Do not really understand where I have to declare some strings of array, could someone assist here please?

Ok, I think I got it now…just added the array of strings in main method like this

static void Main(string args)
{

        Profile sam = new Profile("Sam Drakkila", 30, "New York", "USA", "he/him");

        sam.SetHobbies(new string[] { "golf", "basketball" });
        
        Console.WriteLine(sam.ViewProfile());
        
        
    }

I do not really understand why those hobbies are not printed out…? They are like added to ViewProfile() as understood.