Hi, am trying to build an app that uses the insertion sort method to sort numbers entered in a textbox and display them sorted in a label, so i wrote this inside the sort button click event:
and here is the insertion class:
Although it looks logical to me, it doesn't work and gives an error: Property or indexer 'string.this[int]' cannot be assigned to -- it is read only.
How to get this workin?
Code:
label1.Text = Insertion.insert(textBox1.Text);
Code:
class Insertion
{
public static string insert(string x)
{
for (int i = 2; i < x.Length; ++i)
{
for (int j = i-1; j > 0 && x[j] < x[i]; --j)
{
x[j] = x[i];
}
}
return x.ToString();
}
}
How to get this workin?
Comment