错误CS0029:无法隐式转换类型' int'到'字符串'

时间:2017-01-08 12:32:01

标签: c#

我正在创造一个团结的游戏,但我得到了错误:

  

错误CS0029:无法隐式转换类型' int'到'字符串'。

有谁知道这个芒果?

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;

}

1 个答案:

答案 0 :(得分:1)

试试这个:

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!");
}

但是有一种更好,更优化的方法来连接字符串,试试这个:

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