首页 > 解决方案 > 如何将int变量转换为字符串变量

问题描述

我目前正在从用户将填写三个数字的文本框中拆分一个字符串。我想将这些数字保存为单独的整数。关于如何做到这一点的任何帮助?谢谢你的帮助!

string[] count = txtPoemInput.Text.Split('/');  //Splitting values for keyword numbers

int Poem, Line, Word;

count[0] = Poem.ToString; // Example
count[1] = Line;          // Example
count[2] = Word;

标签: c#stringinteger

解决方案


这是您需要做的。使用 Convert.ToInt32

Poem = Convert.ToInt32(count[0]);
Line = Convert.ToInt32(count[1]);
Word = Convert.ToInt32(count[2]);

推荐阅读