I'm doing a c# forms app for gym workout administration. I have 2 classes: workout and clients.
Clients can have different workouts and workouts can have different exercises, my doubt is how I can add different exercises to my workout classes, because I can have a workout with 5 exercises or with 1, it's a value that is always changing because each client has different needs.
private void button3_Click(object sender, EventArgs e)
{
ex_geral.add_ex(textBox_ex.Text);
lista_exer.Add(ex_geral);
foreach (exercisios_gerais ex in lista_exer)
{
listBox_ex.Items.Add(ex.devolve_ex());
}
}
Now I just need to add an exercise to a workout, but I can't have a number of exercises set, because it's a value that is always changing depending on the client needs.
Use a lista_exer
to store the data entered from the textbox.
Then traverse lista_exer
and pass the traversed data into listBox
.
Code show as below:
namespace WinFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List<string> lista_exer = new List<string>();
lista_exer.Add(textBox_ex.Text.ToString());
foreach (string ex in lista_exer)
{
listBox_ex.Items.Add(ex);
}
}
}
}
Output:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.