방금 C#을 배우기 시작했고 Minecraft 실행기에 대한 간단한 구성 파일 생성기를 무언가와 같이 만들었습니다. Visual C# 2010에서 응용 프로그램을 독립적으로 실행하려고 할 때 문제가 발생했습니다. "인덱스 및 길이는 문자열 내의 위치를 참조해야합니다. 매개 변수 이름 : 길이" 첫 번째 실행시 (빈 텍스트 파일이 만든 후) "인덱스가 배열 범위를 벗어났습니다" 다음에이 인덱스를 다시 시작하면 인덱스가 벗어났습니다.IDE 외부에서 실행될 때 "인덱스가 배열의 경계를 벗어났습니다"
왜 이런 일이 일어나고 있는지 혼란 스럽습니다. 줄 번호를 알려주지 않고 IDE를 통해 응용 프로그램을 실행하지 않을 때만 발생합니다 (디버그 빌드를 실행하든 릴리스 빌드를 실행하든).). 어떤 도움이라도 대단히 감사합니다. 아마도 끔찍한 코딩에 대해 사과드립니다. 저는이 언어의 초보자입니다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Minecraft_Launcher_Config
{
public partial class mcwindow : Form
{
private void outputText(string outtext)
{
output.Text = outtext;
}
private string encrypt(string text, int key)
{
string newText = "";
for (int i = 0; i < text.Length; i++)
{
int charValue = Convert.ToInt32(text[i]);
charValue ^= key;
newText += char.ConvertFromUtf32(charValue);
}
return newText;
}
public mcwindow()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string iuser = "";
string ipass = "";
string imem = "1024";
string iserver = "";
if (System.IO.File.Exists("config.cfg"))
{
System.IO.StreamReader configFile =
new System.IO.StreamReader("config.cfg");
string[] iconfig = System.IO.File.ReadAllLines("config.cfg");
iuser = iconfig[0];
ipass = iconfig[1];
imem = iconfig[2];
iserver = iconfig[3];
configFile.Close();
outputText("Successfully loaded and decrypted config!");
} else
{
System.IO.StreamWriter configwrite = new System.IO.StreamWriter("config.cfg");
configwrite.Close();
outputText("Welcome to Frohman's Minecraft Launcher Config!");
}
username.Text = iuser;
memselect.Value = int.Parse(imem);
int OKey = Convert.ToInt32(username.Text.Substring(0, 1));
string unenpassword = encrypt(ipass, OKey);
password.Text = unenpassword;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void saveexit_Click(object sender, EventArgs e)
{
if (username.Text != "" & password.Text != "")
{
outputText("Saving and exiting!");
int IKey = Convert.ToInt32(username.Text[0]);
string enpassword = encrypt(password.Text, IKey);
string outString = username.Text + System.Environment.NewLine + enpassword + System.Environment.NewLine + memselect.Value + System.Environment.NewLine + serverip.Text;
System.IO.StreamWriter configwrite = new System.IO.StreamWriter("config.cfg");
configwrite.WriteLine(outString);
configwrite.Close();
System.Threading.Thread.Sleep(150);
Environment.Exit(0);
}
else
{
outputText("You're missing some data!");
}
}
private void password_TextChanged(object sender, EventArgs e)
{
}
}
}
'config.cfg' 파일에 4 줄이 있는지 확인하십시오. – Reniuz
그건 그렇고. 디버그 구성을 사용하여 프로젝트를 빌드하면 예외 라인 정보를 얻는 데 도움이됩니다. – MichaelMocko