私はこのコードを書いた、それはいくつかのエラーがあるようです。コンパイラエラーはローカル変数を割り当てていないと言いますが、現在のコンテキストには存在しません。
をloopteller++;
ために、私はこのエラーが
intpos
については
エラー「未割り当てのローカル変数looptellerの使用」を取得する:これらは私が取得していますエラーです
私のコードの目的は、ボタンをクリックすると、ファイルを読み込んでテキストファイルから特定の単語を取得するフォームを作成することです。はい、私はSystem.IO
を使用しています。 looptellerについては
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
}
}
}
}
}
はい - あなたは 'loopteller'をインクリメントしていますが、初期値を指定していません。あなたはそれをすることはできません。 'intpos *'エラーに関しては、実際に宣言している変数、 'intpos1'ではなく' inpost1'を見てください。だから、それらはちょうどタイプミスです(ただし、配列やコレクションを使うほうが良いでしょう)。 –