问题描述
命名空间StringVariables
{
课程计划
{
静态void Main(string [] args)
{
Console.WriteLine(您叫什么名字?");
Console.Write("键入您的名字:");
字符串MyFirstName;
MyFirstName = ReadLine(); - 错误
Console.Write(输入您的姓氏");
字符串MyLastName;
MyLastName = ReadLine(); -- 错误
Console.WriteLine("Hello" + MyFirstName + MyLastName);
}
}
}
namespace StringVariables
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What is Your Name?");
Console.Write("Type Your first name:");
string MyFirstName;
MyFirstName = ReadLine(); -ERROR
Console.Write("Type Your last name");
string MyLastName;
MyLastName = ReadLine(); -ERROR
Console.WriteLine("Hello" + MyFirstName + MyLastName);
}
}
}
这表明在编译后,ReadLine()在此上下文中不存在.
This shows that after compiling ReadLine() does not exist in this context .
1> -------构建开始:项目:StringVariables,配置:调试任何CPU ------
1> C:\ Users \ hp1 \ documents \ Visual Studio 2017 \ Projects \ StringVariables \ StringVariables \ Program.cs(16,27,16,35):错误CS0103:名称'ReadLine'在当前上下文中不存在
1> C:\ Users \ hp1 \ documents \ Visual Studio 2017 \ Projects \ StringVariables \ StringVariables \ Program.cs(19,26,19,34):错误CS0103:名称'ReadLine'在当前上下文中不存在
===========构建:0成功,1失败,0最新,跳过0 ==========
1>------ Build started: Project: StringVariables, Configuration: Debug Any CPU ------
1>C:\Users\hp1\documents\visual studio 2017\Projects\StringVariables\StringVariables\Program.cs(16,27,16,35): error CS0103: The name 'ReadLine' does not exist in the current context
1>C:\Users\hp1\documents\visual studio 2017\Projects\StringVariables\StringVariables\Program.cs(19,26,19,34): error CS0103: The name 'ReadLine' does not exist in the current context
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
推荐答案
谢谢您要在此处发布.
对于您的问题,请更改以下代码.
更改:
MyFirstName = ReadLine(); -Error
MyLastName = ReadLine(); -Error
到:
to:
MyFirstName = Console.ReadLine();
MyLastName = Console.ReadLine();
最佳问候
温迪
这篇关于在Visual Studio 2017中的C#中执行ReadLine()时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!