0

(C# HELP) Keeps Saying Namespace is not found

It's saying that the namespace for, "visitor" and "person" is not found. I'm stuck. Do I have to declare both as strings? ------------------------------------------------------------------------------------------------ using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Person p1 = new vistor(); System.Console.WriteLine("What's your first name?"); p1.fName = System.Console.ReadLine(); System.Console.WriteLine("Now tell me your last name."); p1.lName = System.Console.ReadLine(); System.Console.WriteLine("Please tell me your age now."); p1.Age = int.Parse(System.Console.ReadLine()); p1.Lover = new vistor(); Person.TotalofAllAges + Person.TotalofAllAges + p1.Age; p1.PrintNameAndAge(); System.Console.WriteLine("What's your lover's name?"); p1.Lover.fName = System.Console.ReadLine(); p1.Lover.lName = p1.lName; System.Console.WriteLine("What's their age?"); p1.Lover.age = int.Parse(System.Console.Readline()); p1.Lover.Lover = p1; Person.TotalofAllAges = Person.TotalofAllAges + p1.Lover.Age; p1.Lover.PrintNameAndAge; Console.WriteLine("Press P to go on"); Console.ReadLine(); } } }

2nd Dec 2018, 8:24 PM
SaiyanWarrior15
SaiyanWarrior15 - avatar
2 Réponses
+ 2
Hello, you are instantiating Person and Visitor as class object, but it will not work if you don’t create the Persone and Visitor class object first. for example: public class Person { public string fName; public string lName; } after you create the person class you can use it: public static void Main(string[] args) { Person p = new Person(); p.fName = Console.ReadLine(); p.lName = Console.ReadLine(); Console.WriteLine(p.fName + “ “ + p.lName); } Besides if you declare using System; at the top you dont need to write it everytime like you did: System.Console.ReadLine() -> just write Console.ReadLine()
3rd Dec 2018, 12:02 AM
Sekiro
Sekiro - avatar
+ 1
thank you
3rd Dec 2018, 1:33 AM
SaiyanWarrior15
SaiyanWarrior15 - avatar