C# 我如何解决这个问题;“检测到无法访问的代码”;关于“我的”的错误;如果;陈述
我是C#and编程新手,目前正在一个名叫Marshals Revenue的项目中工作。当我尝试运行该程序时,它告诉我当前上下文中不存在名称“Console”、“WriteLine”、“Write”、“ReadLine”和“Convert”(错误cs0103)。我试图找到解决这个问题的办法,但一直没能解决。有人能帮忙吗。多谢各位C# 我如何解决这个问题;“检测到无法访问的代码”;关于“我的”的错误;如果;陈述,c#,C#,我是C#and编程新手,目前正在一个名叫Marshals Revenue的项目中工作。当我尝试运行该程序时,它告诉我当前上下文中不存在名称“Console”、“WriteLine”、“Write”、“ReadLine”和“Convert”(错误cs0103)。我试图找到解决这个问题的办法,但一直没能解决。有人能帮忙吗。多谢各位 如果有人能帮助我理解这个问题,我在运行程序时也会有一个额外的错误。它告诉我检测到与“if”语句有关的不可访问代码(错误CS0162),并且它不允许我运行代码的处理部分。我
如果有人能帮助我理解这个问题,我在运行程序时也会有一个额外的错误。它告诉我检测到与“if”语句有关的不可访问代码(错误CS0162),并且它不允许我运行代码的处理部分。我不确定为什么会收到错误,因为它看起来语法正确。我还被告知,他们希望包含“CultureInfo.GetCultureInfo”方法。正确的格式是“WriteLine”(“这是一个示例:{0})”,value.ToString(“C”,CultureInfo.GetCultureInfo(“en-US”);”。我不确定这是否与为什么它不会运行我的“如果”语句有关
using System.Globalization;
class MarshallsRevenue
{
static void Main()
{
const int INTERIORPRICE= 500;
const int EXTERIORPRICE=750;
string entryString;
int numberInterior;
int numberExterior;
int revenueInterior;
int revenueExterior;
int total;
bool isInteriorGreater;
// declare the required variables
bool valid;
valid=true;
int Month;
int monthInterPrice=INTERIORPRICE;
int monthExterPrice=EXTERIORPRICE;
// Prompt the user to Enter the month
WriteLine("Enter the number of month being scheduled >>");
// Read the input
entryString = ReadLine();
// convert the input to an integer
Month = Convert.ToInt32(entryString);
Writeline("Enter number of interior murals being scheduled >>");
entryString=ReadLine();
numberInterior = Convert.ToInt32(entryString);
Writeline("Enter number of exterior murals scheduled >>");
entryString = ReadLine();
numberExterior = Convert.ToInt32(entryString);
//use a switch case to perform the aciton
//as per the entered month
switch(Month) {
//set the exterior murals
//to zero for the month
//December through February
case 1:
case 2:
case 12:
numberExterior=0;
break;
//if the month is either
//one of April, May, September
//or October, reduce the price
//of exterior murals.
case 4:
case 5:
case 9:
case 10:
monthExterPrice = 699;
break;
//if the month is either
//July or August
//or October, reduce the price
//of interior murals.
case 7:
case 8:
monthInterPrice = 450;
break;
//Do nothing for the months
//of March June and November.
case 3:
case 6:
case 11:
break;
//if the entered month is invalid,
//display an error message and
//set the is valid month to false.
default:
WriteLine("The entered month is invalid.");
isMonthValid=false;
break;
//if the entered month is valid
//perform the calculations and display
//the results.
if(valid)
{
revenueInterior = numberInterior * monthInterPrice;
revenueExterior = numberExterior * monthExterPrice;
total = revenueExterior + revenueInterior;
isInteriorGreater = numberInterior > numberExterior;
WriteLine("{0} interior mura(ls are scheduled at {1} each for a total of {2}", numberInterior, monthInterPrice.ToString("C"), revenueInterior.ToString("C"));
WriteLine("{0} exterior murals are scheduled at {1} each for a total of {2}", numberExterior, monthExterPrice.ToString("C"), revenueExterior.ToString("C"));
WriteLine("Total revenue expected is {0}", total.ToString("C"));
WriteLine("It is {0} that there are more interior murals sceduled than exterior ones.", isInteriorGreater);
}
}
}
}
Console
是系统名称空间的一部分,因此确保使用系统时有代码>在顶部。一旦包含了这些,您将需要通过在控制台上调用来修复读/写线调用。控制台是系统名称空间的一部分,因此请确保使用System代码>在顶部。一旦包含该名称空间,您将需要通过在控制台上调用来修复读/写在线调用。您缺少导入系统
名称空间,并且有3个选项:
- 始终使用命名空间限定表达式:
System.Console.Writeline()代码>
- 添加
使用系统编码>并在通话前添加控制台。
- 使用静态导入
使用静态系统控制台代码>并且您可以保持代码不变
您缺少系统
命名空间的导入,有3个选项:
- 始终使用命名空间限定表达式:
System.Console.Writeline()代码>
- 添加
使用系统编码>并在通话前添加控制台。
- 使用静态导入
使用静态系统控制台代码>并且您可以保持代码不变
文件顶部缺少一个使用System
的。而那些其他名称(如WriteLine
)是System.Console
类的静态方法。您可以使用系统添加代码>位于代码的顶部,并像Console.WriteLine(“要写的东西”)那样调用它们
或者像System.Console.WriteLine(“不使用而写一行”)
感谢您帮助澄清了这一点。您的文件顶部缺少一个使用System
的。其他名称(如WriteLine
)是System.Console
类的静态方法。您可以使用系统添加代码>位于代码的顶部,并像Console.WriteLine(“要写的东西”)那样调用它们
或者像System.Console.WriteLine(“不使用而写一行”)代码>谢谢你帮我澄清了更多。谢谢你帮了我很多。谢谢你帮助我理解它。我在运行程序时还有一个额外的错误。它告诉我检测到与“if”语句有关的不可访问代码(错误CS0162),并且它不允许我运行代码的处理部分。我不确定为什么会收到错误,因为它看起来语法正确。我还被告知,他们希望包含“CultureInfo.GetCultureInfo”方法。正确的格式是“WriteLine”(“这是一个示例:{0})”,value.ToString(“C”,CultureInfo.GetCultureInfo(“en-US”);”。我不确定这是否与为什么它不会运行我的“如果”声明有关。谢谢你帮了我很多忙。谢谢你帮助我理解它。我在运行程序时还有一个额外的错误。它告诉我检测到与“if”语句有关的不可访问代码(错误CS0162),并且它不允许我运行代码的处理部分。我不确定为什么会收到错误,因为它看起来语法正确。我还被告知,他们希望包含“CultureInfo.GetCultureInfo”方法。正确的格式是“WriteLine”(“这是一个示例:{0})”,value.ToString(“C”,CultureInfo.GetCultureInfo(“en-US”);”。我不确定这是否与为什么它不会运行我的“如果”语句有关。谢谢你,我做到了,它成功了。我很感激,谢谢你,我做到了,而且成功了。我很感激。