简体   繁体   English

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

[英]Error CS0029: Cannot implicitly convert type 'int' to 'string'

I am creating a game in unity but im getting the error:我正在统一创建游戏,但出现错误:

error CS0029: Cannot implicitly convert type 'int' to 'string'.错误 CS0029:无法将类型“int”隐式转换为“string”。

Does anyone know the awnser?有谁知道awser吗?

public Text text;

int max;
int min;
int guess;

void Start () {

    text.text = ("Pick a number in your head between " + min);
    text.text =  + max;
    text.text = (" , but dont tell me!");

    max = 1000;
    min = 1;
    guess = 500;

}

Try this:尝试这个:

public Text text;

int max;
int min;
int guess;

void Start () {
    max = 1000;
    min = 1;
    guess = 500;

    text.text = ("Pick a number in your head between " + min.ToString());
    text.text += max.ToString();
    text.text += (" , but dont tell me!");
}

But there is a better and more optimized way to concatenate strings, try this:但是有一种更好、更优化的方法来连接字符串,试试这个:

public Text text;

int max;
int min;
int guess;

void Start () {
    max = 1000;
    min = 1;
    guess = 500;

    text.text = string.Format("Pick a number in your head between {0} and {1}, but dont tell me!", min.ToString(), max.ToString());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 CS0029:无法将类型“string”隐式转换为“int” - Error CS0029: Cannot implicitly convert type 'string' to 'int' 错误 CS0029:无法将类型“System.DateTime”隐式转换为“int”(CS0029)(DeclaringConstructor) - Error CS0029: Cannot implicitly convert type 'System.DateTime' to 'int' (CS0029) (DeclaringConstructor) 错误CS0029:无法将类型'int'隐式转换为'Score' - error CS0029: Cannot implicitly convert type 'int' to 'Score' 错误 CS0029 无法将类型“字符串”隐式转换为“双精度” - Error CS0029 Cannot implicitly convert type 'string' to 'double' 错误CS0029无法将类型“字符串”隐式转换为“十进制” - Error CS0029 Cannot implicitly convert type 'string' to 'decimal' 编译器错误消息:CS0029:无法将类型“int”隐式转换为“string”错误 - Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to 'string' error 编译器错误消息:CS0029:无法将类型“int”隐式转换为“string” - Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to 'string' CS0029:无法将类型'int'隐式转换为'bool' - CS0029: Cannot implicitly convert type 'int' to 'bool' CS0029 C#无法将类型隐式转换为'string []' - CS0029 C# Cannot implicitly convert type to 'string[]' 错误CS0029:无法将类型'int'隐式转换为'bool'-Unity3D - error CS0029: Cannot implicitly convert type `int' to `bool' - Unity3D
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM