이것을 시도 할 때마다 벽돌 벽을 돌고 있습니다. 내가 알아 내지 못한 것은 내 코드가 내 정보를 텍스트 파일에서 가져 와서 정렬하지 않는 이유입니다. 내가 한 모든 일은 좋게 보입니다. 76, 86 및 103 행에서 3 개의 오류가 발생합니다. 'yourChoicesItems'은 현재 컨텍스트에 존재하지 않으며 yourChoicesPrices '는 현재 컨텍스트에 존재합니다. 하지만 나는 무엇이 잘못되었는지 보지 못합니다. 다음과 같은 날짜를 넣을 때 : public string [] yourChooseItems = {etc ....} 작동합니다. 왜이 기능이 작동하지 않습니까?파일에서 텍스트를 사용하여 정렬하려고 시도합니다.
내 텍스트 파일은 다음과 같습니다
BlueberryBagels 0.75
해시 브라운 (A 각 줄 앞에 공간이) 2.50
BottledSoda 1.50
커피 0.90
도넛 1.50
감자 튀김 1.50
BlueberryMuffins 0.85
LiteYogurt 0.75
HotChocolate 1.75
Onio nSoup 3.00
PecanPie 2.75
PurpleYam 2.75
StrawberryBagels 0.80
토스트 2.00
VanillaIceCream 2.75
IcedTea 1.00
using System.IO;
namespace testce
{
public partial class MainScreen : Form
{
static void InsertSort(IComparable[] array)
{
int i, j;
for (i = 1; i < array.Length; i++)
{
IComparable value = array[i];
j = i - 1;
while ((j >= 0) && (array[j].CompareTo(value) > 0))
{
array[j + 1] = array[j];
j--;
}
array[j + 1] = value;
}
}
int count = 0;
double totalTax = 0;
double totalSale = 0;
public MainScreen()
{
FileStream fStream = new FileStream("menu.txt", FileMode.Open, FileAccess.Read);
StreamReader inFile = new StreamReader(fStream);
string inValue;
string[] values;
double price;
List<string> lines = new List<string>();
while (!inFile.EndOfStream)
{
inValue = inFile.ReadLine();
lines.Add(inValue);
values = (inValue.Split(" ".ToCharArray()));
price = double.Parse(values[2]);
InsertSort(values);
}
inFile.Close();
InitializeComponent();
InitializeControls();
for (int index = 0; index < listBox.SelectedIndices.Count; index++)
{
subTotal = subTotal + yourChoicesPrices[listBox.SelectedIndices[index]];
}
for (int index = 0; index < listBox.SelectedIndices.Count; index++)
{
textBox.AppendText(yourChoicesItems[listBox.SelectedIndices[index]] + "\n");
}
Text = "Thank you for using Food Systems Inc.";
this.listBox.DataSource = yourChoicesItems;
this.btnOne.Text = "Place Order";
this.label.Text = "Menu Selection";
this.labell.Text = "Order Information";
}
public System.Windows.Forms.ListBox listBox;
private System.Windows.Forms.Label label;
private System.Windows.Forms.Button btnOne;
private System.Windows.Forms.TextBox textBox;
}
}
일반적인 지침으로, 주어진 문제에 대해 너무 많은 코드입니다. 읽을 수 있도록 노력하십시오. –
휠을 재발 명하지 마십시오. 배열을 정렬하는 것은 해결 된 문제입니다. 정렬 알고리즘을 직접 작성하지 않고 .NET에서 여러 가지 방법으로이를 수행 할 수 있습니다. 예를 들어'Array.Sort' 만 사용할 수 있습니다. –
@ThomasLevesque - 이것은 학습 운동의 모든 흔적을 가지고 있으며, 일반적으로 뭔가를 재창조하는 것에 관한 것입니다. –