I've been using Array.Sort() to sort an array of string, but for some reason it is keeping the first element of the array and outputting not in order.
private void quicksort1_Click(object sender, EventArgs e)
{
String[] parts = new String[1000];
//System.IO.StreamReader file = new System.IO.StreamReader(textBox1.Text);
System.IO.StreamWriter output = new System.IO.StreamWriter("OUTPUT.txt");
parts = File.ReadAllLines(textBox1.Text);
foreach (string s in parts)
{
Array.Sort(parts);
parts.Equals(s);
output.WriteLine(s);
counter++;
}
output.WriteLine("There were" + " " + counter + " " + "lines read in.");
output.Close();
I was just wondering if there was a possible solution to where Array.Sort() would sort the first element as well as the others.
partsobject when it is being referenced by theforeachloop may have some unintended side-effects. Have you tried moving theArray.Sort(parts);statement to before the start of the loop?