Jump to content

use of arrays

- - - - -

  • Please log in to reply
1 reply to this topic

#1
cesarg

cesarg

    Newbie

  • Members
  • Pip
  • 9 posts
hello
i am having dificulty showing the results of a circuit, that has series and parallel resistors. as i am using two different forms everytime i send the results to the
listbox where they are to be stored. i think one set of results overrides the other because when i open the results form the list box is empty. i think that this is due to the amount of sets of resistors (serie or parallel) that the circuit contains. for example if the circuit contains 5 different sets 5 forms will appear. if a set is in series the series form will appear, if it is in parallel a parallel form will appear.
if (cantidad == cont)
{



for (int j = 0; j < listBox1.Items.Count; j++)
{
rt += 1 / Convert.ToDouble(listBox1.Items[j].ToString());

}
rE = 1 / rt;
it = (voltaje / rE);

Resultados resu1 = new Resultados();
resu1.listBox3.Items.Add("Resistencia total: " + " " + rE.ToString("#.###") + " " + "Ohms");
resu1.listBox3.Items.Add("Corriente total: " + " " + it.ToString("#.###") + " " + "Ampere");

for (int a = 0; a < listBox1.Items.Count; a++)
{
resu1.listBox3.Items.Add("Corriente en Resistor: " + " " + (a + 1).ToString());
resu1.listBox3.Items.Add(voltaje / Convert.ToDouble(listBox1.Items[a].ToString()));
}
this is the code i am using for the form in parallel to obtain amount of resistance and current. the series form is similar. all results go to listbox3 in the form Resultados. i would like to use an array to store all the amounts of total resistance that will be generated...but i dont know how...if someone could lend a hand???

#2
Alex69

Alex69

    Newbie

  • Members
  • Pip
  • 1 posts
Create a class which has properties for Current and Resistance, and store instances of that class in the array.

public class MyClass
{
public double Current { get; set; }
public double Resistance { get; set; }
}

MyClass[] results = new MyClass[2];

btw I advise to use Collection or List instead of array, because it allows to add as many elements as you need, and you do not need to know its size when you declare your array

List<MyClass> results = new List<MyClass>();




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users