The object of Your Affection step 8

Hi there, currently stuck on step 8 when trying to print out sam to the console. Im getting these errors and I just cant figure out were im going wrong. I tried to follow the video the shows step by step how this is done but mine results in errors.

Profile.cs(32,61): error CS1010: Newline in constant [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(32,62): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,24): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,25): error CS1056: Unexpected character ‘’ [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,36): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,36): error CS1513: } expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,47): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,48): error CS1010: Newline in constant [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,50): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]

The build failed. Fix the build errors and run again.

when trying to run this in my main:

using System;

namespace DatingProfile

{

class Program

{

static void Main(string[] args)

{

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

Console.WriteLine(sam.ViewProfile());

 

}

}

}

and this is my Profile.cs:

using System;

namespace DatingProfile

{

class Profile

{

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")

{

this.name = name;

this.age = age;

this.city = city;

this.country = country;

this.pronouns = pronouns;

this.hobbies = new string[0];

}

public string ViewProfile()

{

  string bio = $"Name: {name}\nAge: {age}\nCity: {city}\n

  Country: {country}\n Pronouns: {pronouns}";

  return bio;

}

}

}

Hi! Welcome to the forums :slight_smile:

Can you repost your code pressing </> before you paste (to format it).
It seems like the issue is syntax, so if it’s formatted people will be able to pick out the errors quickly.

These are my errors

Profile.cs(32,61): error CS1010: Newline in constant [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(32,62): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,24): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,25): error CS1056: Unexpected character ‘’ [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,36): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,36): error CS1513: } expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,47): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,48): error CS1010: Newline in constant [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]
Profile.cs(33,50): error CS1002: ; expected [/home/ccuser/workspace/csharp-dating-profile/DatingProfile.csproj]

The build failed. Fix the build errors and run again.

This is my Program.cs :slight_smile:

using System;

namespace DatingProfile

{

class Program

{

static void Main(string[] args)

{

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

Console.WriteLine(sam.ViewProfile());

 

}
}

}

This is my Profile.cs

using System;

namespace DatingProfile

{

class Profile

{

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")

{
this.name = name;

this.age = age;

this.city = city;

this.country = country;

this.pronouns = pronouns;

this.hobbies = new string[0];

}

public string ViewProfile()

{

  string bio = $"Name: {name}\nAge: {age}\nCity: {city}\n

  Country: {country}\n Pronouns: {pronouns}";

  return bio;

}
}

}


Apologies about that! I hope its formatted correctly now. :slight_smile:

Hi,

At least with this code the first problem arose from the indentation (maybe it’s different in your text editor). Line 33 error might be this line (not sure) but the issue would be is you can’t just have this in two lines or the compiler will treat it as 2 diff entries:

string bio = $"Name: {name}\nAge: {age}\nCity: {city}\n

Country: {country}\n Pronouns: {pronouns}";
  • The other thing I don’t see is a Main class.

  • And probably this will throw an error this.hobbies = new string[0]; Since hobbies is not a string[]. If you edit your hobbies declaration as a string[] instead of a string you can have that statement (if that’s what you’re going for).

It’s not perfect but I played with the indentation to give you an idea of what it could look like, this way it’s easier to track what belongs to what.

using System;

namespace DatingProfile

{

    class Profile{

        private string name;
        private int age;
        private string city;
        private string country;
        private string pronouns;
        private string[] hobbies; // this is different

        public Profile(

            string name, 
            int age, 
            string city, 
            string country,
            string pronouns = "they/them")

            {
                this.name = name;
                this.age = age;
                this.city = city;
                this.country = country;
                this.pronouns = pronouns;
                this.hobbies = new string[0];
            }

        public string ViewProfile(){

            string bio = $"Name: {name}\nAge: {age}\nCity: {city}\n Country: {country}\n Pronouns: {pronouns}";
            return bio;
        }
    }
}
string bio = $"Name: {name}\nAge: {age}\nCity: {city}\n

Country: {country}\n Pronouns: {pronouns}";

Is what caused the issue. I would never of thought that 2 lines would’ve created the issue. I was trying to make it seem a bit more organized! This is something i wouldnt of solved without it being pointed out, thankyou a whole bunch!

1 Like