struct SSales
{
private int[] _years;
private double[] _sales;
private Random salesran;
public SSales (int [] yeararr, double[] salesarr)
{
//yeararr = Enumerable.Range(2000, 10).ToArray();
_years = yeararr;
_sales = salesarr;
double max = 50000.00;
double min = 1000.00;
salesran = new Random();
for (int i = 0; i < yeararr.Length; i++)
{
for (int j = 0; j < salesarr.Length; j++)
{
salesarr[j] = Math.Round((salesran.NextDouble() * (max - min) + min), 2);
}
}
}
public override string ToString()
{
string itemstring; //string.join?
return itemstring;
}
Hi! I'm a new C# student, and I'm having a little difficulty using structures. When the generatebutton is pressed, it's supposed to call the struct SSales and generate 10 random sales numbers for each year and input them into the listbox using a ToString override as shown in the above image.
EDIT the tostring override should format like:
int[]year + "empty space" + "$" + double[]sales.
I MUST use int[] and double[].
I know I'm supposed to use string.Join, but I can't figure out how to combine two arrays of different types into a string array. Generating the array works fine, I tested it out, all I need is to know how to use the ToString override. Any help would be appreciated!
EDIT 2 I should also note that I'm also using bubble sort to organize these after generation, which will probably complicate some answers.
private void Sortbutton_Click(object sender, EventArgs e)
{
if (yearradio.Checked)
{
int temp = 0;
for (int i = 0; i < yeararr.Length; i++)
{
for (int j = 0; j < yeararr.Length; j++)
{
if (yeararr[i] < yeararr[j])
{
temp = yeararr[i];
yeararr[i] = yeararr[j];
yeararr[j] = temp;
}
}
}
}
if (salesradio.Checked)
{
double temp2 = 0.0;
for (int i = 0; i < salesarr.Length; i++)
{
for (int j = 0; j < salesarr.Length; j++)
{
if (salesarr[i] > salesarr[j])
{
temp2 = salesarr[i];
salesarr[i] = salesarr[j];
salesarr[j] = temp2;
}
}
}
}
// for (int i = 0; i < yeararr.Length; i++)
// {
// for (int j = 0; j < salesarr.Length; j++)
// {
// listBox1.Items.Add();
// }
// }
}