C# 返回错误“无法将类型‘int’隐式转换为‘string’”,即使没有给出 int

死亡华尔兹

我正在运行此代码:

using System;

class MainClass {
  public static void Main (string[] args) {
   Console.WriteLine("What is your name?");
   string lol = Console.Read ();
   Console.WriteLine (lol);
  }
}

并收到此错误:

main.cs(6,25): error CS0029: Cannot implicitly convert type `int' to `string'
Compilation failed: 1 error(s), 0 warnings
compiler exit status 1

虽然我没有int value在给定的代码中明确声明 an ,但这是我阅读的其他文章中的原因。

乔尔·科霍恩

Console.Read()返回int下一个单个字符值。你可能想要Console.ReadLine().

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法将类型'int'隐式转换为'bool'Unity

为什么在C ++中将int隐式转换为long long int会给出意外的答案?

错误:无法将int类型的表达式...隐式转换为ubyte

C#-尝试将两个字节转换为ushort,导致“无法将类型'int'隐式转换为'ushort'”错误

在C#中减去整数时出现错误“无法将int隐式转换为short”

无法将类型“ double”隐式转换为“ int”

无法将类型'int'隐式转换为'string'c#

错误C2664:'print_result':无法将参数1从'int(__cdecl *)(int,int,int)'转换为'int'

无法将类型int []隐式转换为int?[]

无法在C#中将类型字符串隐式转换为int

无法将类型'double'隐式转换为'int'。-错误

Unity3D-错误-无法将类型'int'隐式转换为'string'

webservice无法构建-“无法将类型'string'隐式转换为'int'”

ARC不允许将非目标C指针类型'int *'隐式转换为'Bird *'

无法将类型隐式转换为int []

错误消息“无法将类型'String'隐式转换为'Int'”

C#:错误-无法将类型'int'隐式转换为'System.Collections.Generic.IEnumerable <double>'

无法将类型'float'隐式转换为'int'

无法将类型“string”隐式转换为“int”以比较 2 个变量

错误 2 无法将类型“int”隐式转换为“string”c#

C# - 无法将类型“int”隐式转换为“int[][]” - CodeFights

C# 不能隐式转换类型“int?” 'int'

无法将类型 'IEnumerable<int> 隐式转换为 'int'

无法将类型对象隐式转换为 int 错误组合框

Python:错误“类型错误:无法将 int 隐式转换为 str”

C# - 不能将类型“string[][]”隐式转换为“int[][]”

无法将类型“bool”隐式转换为“int”

c# - 如何修复停止“无法将int类型隐式转换为bool”错误代码

无法将类型“int”隐式转换为“bool”