我一直对这个stringcodes程序:
string[] keywords = { "abstract", "as", "etc" };
它的工作我使用这个代码后(在mainform.cs)时间:
for (int i = 0; i < keywords.Length; i++)
{
if (keywords[i] == token)
{
// Apply alternative color and font to highlight keyword.
rtb.SelectionColor = Color.Blue;
rtb.SelectionFont = new Font("Courier New", 10, FontStyle.Bold);
break;
}
}
但事情是我想使单独的类(KeyWord.cs)关键字和MainForm的声明,但这个代码不工作:
KeyWord.cs:
namespace editor
{
class KeyWord
{
string[] keywords = { "abstract", "as", "etc" };
}
}
Mainform.cs:
string[] keywords;
for (int i = 0; i < keywords.Length; i++)
{
if (keywords[i] == token)
{
// Apply alternative color and font to highlight keyword.
rtb.SelectionColor = Color.Blue;
rtb.SelectionFont = new Font("Courier New", 10, FontStyle.Bold);
break;
}
}
错误说:
未分配的局部变量“关键字”使用:
注意,此代码在MainForm中的空隙条件下:
private void TextChangedEvent(object sender, EventArgs e)
{
}
我该怎么办?