Reputation:
I'm having a problem printing out an array that I have created through a function.
All it says in the MessageBox
is System.int32[]
, what have I done wrong?
private int[] sekunder(int tid)
{
int sekunder, minuter, timmar;
sekunder = tid;
minuter = sekunder / 60;
timmar = minuter / 60;
int[] beräknaTid = { sekunder, minuter, timmar };
return beräknaTid;
}
private void button1_Click(object sender, EventArgs e)
{
int tid;
tid = Convert.ToInt32(textBox1.Text);
MessageBox.Show(Convert.ToString(sekunder(tid)));
}
Upvotes: 1
Views: 1359
Reputation: 10285
try this:
Array Contains Multiple Elements You Need to Iterate through them
private void button1_Click(object sender, EventArgs e)
{
int tid;
tid = Convert.ToInt32(textBox1.Text);
foreach (var item in sekunder(tid))
{
MessageBox.Show(Convert.ToString(item));
}
// for comma separated
//use this : MessageBox.Show(string.Join(",",sekunder(tid)))
}
Upvotes: 1
Reputation: 20754
you can also join all values in your array and show them
private void button1_Click(object sender, EventArgs e)
{
int tid;
tid = Convert.ToInt32(textBox1.Text);
MessageBox.Show(string.Join(", ",sekunder(tid)));
}
Upvotes: 1