we have this work that asks for us to solve for the arithmetic progression, and show its output on a textbox.
this is how i started my plans..
textbox1 ask for initial value
textbox2 ask for sequence value
then after pressing compute button
sequence will be stored in an array
the sequence will be printed on the texbox3

i can't seem to find the exact keyword is there was... all i need is to print the contents of the values that will be stored in an array.
here's my scratch code:

initVal = double.Parse(textBox1.Text);
SeqVal = int.Parse(textBox2.Text);
double[] arraySeq = new double[SeqVal];
for (meow = 0; meow < SeqVal; meow++)
{
tempor += initVal;
arraySeq[meow] = tempor;
                        
                       
}
label3.Show();
textBox3.Show();
 textBox3.Text = Convert.ToString(arraySeq[2]);

Edited 5 Years Ago by existinglady: putting code snipets

For-loop?

if(arraySeq.Length > 0)
{
    StringBuilder builder = new StringBuilder(arraySeq.ToString());
    for(int i = 0; i < arraySeq.Length; i++)
        builder.Append(", ").Append(arraySeq[i]);
    textBox3.Text = builder.ToString();
}
else
    textBox3.Text = string.Empty;

For-loop?

if(arraySeq.Length > 0)
{
    StringBuilder builder = new StringBuilder(arraySeq.ToString());
    for(int i = 0; i < arraySeq.Length; i++)
        builder.Append(", ").Append(arraySeq[i]);
    textBox3.Text = builder.ToString();
}
else
    textBox3.Text = string.Empty;

Your Implementation does work sir, but when I tried it on my program,
a "System.Double[]" appears before the contents
e.g.
System.Double[],1,1
I don't know how that thing showed up

StringBuilder builder = new StringBuilder(arraySeq[0].ToString());

Apologies, replace line 3 with the line above. I referenced the array instead of the first element.

You can use String.Join() method if you data are in stirng array:

string[] arr = { "a", "b", "c" };
string str = String.Join(" ", arr);  //copy str to textBox.Text property

In case if your array is not string array ,you can do it like this:

double[] arrD = { 2.2, 4.5, 6.4 };
 string str2 = String.Join(" ", arrD.Select(s => s.ToString()).ToArray());
StringBuilder builder = new StringBuilder(arraySeq[0].ToString());

Apologies, replace line 3 with the line above. I referenced the array instead of the first element.

can you tell me what happened there? I can't understand it yet, but as I have replaced it, it did work!

This article has been dead for over six months. Start a new discussion instead.