Access attributes from a class arraylist c #

0

I have to create a menu where one of its options sets the value of the attribute of a class, that class already has its objects instantiated and saved in an arraylist. The question is how do I access that attribute?

class Producto
{
    public string tipo;
    public double precio;
    public Producto (){}
 }

and so objects are added to the list:

Console.Write("¿Cuantos productos quiere dar de alta? ");
int i = int.Parse(Console.ReadLine());
Console.WriteLine("");

for( int o = 1 ; o <= i ; o++ )
{
    Producto a = new Producto();
    lista.Add(a);
}

What I have to do is to add certain products to a certain "discount" variable, which I then want to add to the array

    
asked by Ludmila Belen 19.06.2018 в 02:07
source

1 answer

0

Within the method where you have declared the arraylist try to make the arraylist return. Here is an example of a code of mine.

public static List<Partitura> LeerPartitura()
    {
        List<Partitura> partituras = new List<Partitura>();
        partituras.Add(new Partitura() { Note = 1, Time = 2 });
        partituras.Add(new Partitura() { Note = 2, Time = 1 });
        partituras.Add(new Partitura() { Note = 1, Time = 2 });
        return partituras;
    }

After this you create the variable, and assign it the value that the method returns, and it would look something like this: List<Partitura> partituras = PartiturasFlauta.LeerPartitura(); In my case, do not use ArrayList, use list but it's very similar.

public static ArrayList DevolverArraylist()
    {
        ArrayList array = new ArrayList();
        //Aqui asignas los valores.
        return array;
    }
    
answered by 19.06.2018 в 02:17