我写了这段代码,它似乎有一些错误。这些是我得到的错误:
因为loopteller++;
我收到错误“使用未分配的局部变量 loopteller”
对于我所有的intpos
我都收到此错误“在当前上下文中不存在”
我的代码的目标是创建一个表单,当我点击一个按钮时,它可以读取文件并从我的文本文件中获取特定的单词。是的,我正在使用System.IO
.
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string interface1 = "";
string interface2 = "";
string interface3 = "";
string interface4 = "";
int inpost1 = 0;
int inpost2 = 0;
int inpost3 = 0;
int inpost4 = 0;
int teller = 0;
int interfaceteller = 0;
int loopteller;
string[] routerconfig = File.ReadAllLines("c:\\naamcomputer\\pt.txt");
foreach(string configregel in routerconfig)
{
loopteller++;
if (configregel.Contains("interface Gigabitethernet"))
{
teller++;
if(teller == 1)
{
interface1 = configregel;
intpos1 = loopteller;
}
else if(teller == 2)
{
interface2 = configregel;
intpos2 = loopteller;
}
else if (teller == 3)
{
interface3 = configregel;
intpos3 = loopteller;
}
else if (teller == 4)
{
interface4 = configregel;
intpos4 = loopteller
}
}
}
}
}