嗨,这是我的代码,我想在列表中添加字符串,但出现此错误
use of unassigned local variable
这是我的代码
List<string> tokens = new List<string>();
int token_number=0 ;
char[] character = file_text.ToCharArray();
int i = 0;
for (; i < character.Length; i++)
{
if (char.IsLetter(character[i]))
{
string local_token;
while (char.IsLetterOrDigit(character[i + 1]) || character[i + 1] == '_')
{
local_token += character[i];
tokens.Add(local_token.ToString());
}
}
}
嗨,这是我的代码,我想将字符串添加到我的列表中,所以得到这个错误 Error 2 Use of unassigned local variable 'local_token' C:\Users\Alireza\Documents\Visual Studio 2013\Projects\tslnc\tslnc\Program.cs 46 25 tslnc
最佳答案
将您的 local_token 声明更改为:
string local_token = "";
如果您没有为字符串指定值,则它不会被初始化(未分配)。
关于c# 使用未赋值的局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33825443/