0% found this document useful (0 votes)
34 views3 pages

Parte I: Clase de La Pregunta 2: Class1

The document contains code for a C# Windows Forms application. It defines a Class1 class with string and int properties for a course name and credits. It also has code to add Class1 objects to a list, display them in list boxes, sort the list, and calculate total credits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Parte I: Clase de La Pregunta 2: Class1

The document contains code for a C# Windows Forms application. It defines a Class1 class with string and int properties for a course name and credits. It also has code to add Class1 objects to a list, display them in list boxes, sort the list, and calculate total credits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PARTE I : CLASE DE LA PREGUNTA 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication2
{
class Class1
{
string materia;
int credito;

public string Materia


{
get
{
return materia;
}

set
{
materia = value;
}
}

public int Credito


{
get
{
return credito;
}

set
{
credito = value;
}
}

public Class1(string materia,int credito)


{
this.Materia = materia;
this.Credito = credito;

public Class1()
{

}
}
PARTE II : CODIGO
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
/* List<string> nombres = new List<string>();
List<int> edad = new List<int>();
List<string> genero = new List<string>();*/
Class1 prueba;
List<Class1> auxiliar = new List<Class1>();
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{

listBox1.Items.Clear();
listBox2.Items.Clear();

agregar_a_la_lista();

for (int i=0;i<auxiliar.Count;i++)


{
listBox1.Items.Add(auxiliar[i].Materia);
listBox2.Items.Add(auxiliar[i].Credito);

}
textBox1.Text = "";
textBox2.Text = "";

}
public void agregar_a_la_lista()
{
prueba = new Class1(textBox1.Text, int.Parse(textBox2.Text));
auxiliar.Add(prueba);

private void button2_Click(object sender, EventArgs e)


{

private void button3_Click(object sender, EventArgs e)


{

listBox1.Items.Clear();
listBox2.Items.Clear();
IEnumerable<Class1> listaordenada = auxiliar.OrderBy(user => user.Materia);
List<Class1> auxiliar2 = listaordenada.ToList<Class1>();
foreach (Class1 user in listaordenada)
{
listBox1.Items.Add(user.Materia);
listBox2.Items.Add(user.Credito);

private void button4_Click(object sender, EventArgs e)


{

private void button5_Click(object sender, EventArgs e)


{
int i = 0, result = 0;
while (i < listBox2.Items.Count)
{
result += Convert.ToInt32(listBox2.Items[i++]);
}

textBox3.Text = Convert.ToString(result);
}
}
}

You might also like