C#help表示命名空间错误 [英] C# help says namespace error

查看:50
本文介绍了C#help表示命名空间错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它说没有找到访客和人的名称空间。我被卡住了。我必须将两者都声明为字符串吗?我的作业是



创建一个名为Person的类,它具有以下公共成员变量:
$ b $b年龄(int)
$ b $bFirstName(字符串)
$ b $bLastName(字符串)
$ b $b配偶(人)

Person类也应该具有以下公共静态变量:
$ b $bSumOfAllAges(double)

Person类还应具有以下公共方法:
$ b $bGetFullName(字符串)
$ b $bPrintNameAndAge(void)

在主程序中,您将声明两个名为p1和p2的Person类型的变量。

要求用户向您提供这两个人的姓名,年龄和婚姻状况。

此外,还要询问其配偶的名字和年龄。

当你这样做时,跟踪你所做的静态变量中所有年龄的总和。

你可以假设配偶自动获得与个人相同的姓氏。

不要忘记将配偶变量设置为适合所有四个人的值。

收集此信息后:
$ b $b调用PrintNameAndAge() 四个人中的每个人。
$ b $b打印出单身人口的平均年龄。 (SumOfAllAges / 4)

主程序本地可能只有2个人类型变量。 (p1和p2)

配偶必须通过p1.Spouse和p2.Spouse变量引用。



- --------------------------------------------



我尝试过:



使用系统;

使用System.Collections.Generic;

使用System.Linq;

使用System.Text.RegularExpressions;

命名空间Rextester

{

公共课程

{

public static void Main(string [] args)

{

Person p1 = new vistor();

System.Console.WriteLine(你叫什么名字?);

p1.fName = System.Console.ReadLine();

System.Console.WriteLine(现在告诉我你的姓氏。);

p1.lName = System.Console。 ReadLine();

System.Console.WriteLine(请告诉我你现在的年龄。);

p1.Age = int.Parse(System.Console.ReadLine ());

p1.Lover = new vistor();

Person.Totalo fAllAges + Person.TotalofAllAges + p1.Age;

p1.PrintNameAndAge();

System.Console.WriteLine(你爱人的名字是什么?);

p1.Lover.fName = System.Console.ReadLine();

p1.Lover.lName = p1.lName;

System.Console.WriteLine (他们的年龄是多少?);

p1.Lover.age = int.Parse(System.Console.Readline());

p1.Lover.Lover = p1;

Person.TotalofAllAges = Person.TotalofAllAges + p1.Lover.Age;

p1.Lover.PrintNameAndAge;

Console.WriteLine( 按P继续);

Console.ReadLine();

}

}

}

It's saying that the namespace for, "visitor" and "person" is not found. I'm stuck. Do I have to declare both as strings? My Assignment was to

Create a class called "Person" that has the following public member variables:
 Age (int)
 FirstName (string)
 LastName (string)
 Spouse (Person)
The Person class should also have the following public static variable:
 SumOfAllAges (double)
The Person class should also have the following public methods:
 GetFullName (string)
 PrintNameAndAge (void)
In your main program, you will declare two variables of type Person named "p1" and "p2".
Ask the user to provide you with the name, age, and marital status of both individuals.
Also, ask for the first name and age of their spouses.
While you are doing this, keep track of the sum of all ages in the static variable you made.
You can assume the spouse automatically gets the same last name as the individual.
Don’t forget to set the "Spouse" variable to the appropriate value for all four people.
After you have collected this information:
 Invoke "PrintNameAndAge()" on each of the four people.
 Print out the single average age of the people. (SumOfAllAges / 4)
You may only have 2 "Person" type variables local to the Main Program. (p1 and p2)
The spouses must be referenced through the "p1.Spouse" and "p2.Spouse" variables.

---------------------------------------------

What I have tried:

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();
}
}
}

推荐答案

基本上,它不知道你在寻找什么,但它找不到它 - 所以它假定它是一个命名空间并将错误报告为命名空间问题。

但事实并非如此 - 这是因为你没有遵循指示。再次阅读你的作业,并注意它所说的位
Basically, it doesn't know what you are looking for, but it can't find it - so it assumes it's a namespace and reports the error as a namespace problem.
But it isn't - it's that you haven't followed instructions. Read your homework again, and pay attention to the bit where it says
Quote:

创建一个名为Person的类,它具有以下公共成员变量...

Create a class called "Person" that has the following public member variables ...



提示:操作词是创建。


Hint: the operative word is "create".


这篇关于C#help表示命名空间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆