0

I have the following code:

Informacion informacion = new Informacion(); // crea un objeto de la clase 
InformacionArrayList AInformacion = new ArrayList(); // crea la ArrayList para llevar esta informacion

                // La siguiente linea tiene un objeto de la clase como prueba, esta esta quemada dentro de las funciones
                AInformacion.Add(new Informacion(01, "Quedamo", null, "Jose Mora", "josemora@prueba.com", "047-1234567-1", "cosas sobre mi", "Ingeniero en sistema", "Habilidades", "Experiencia en el area", "Referencia de X persona", "Mis pasatiempos"));
                AInformacion.Add(new Informacion(02, "Rostizado", null, "Jesus Grullon", "josemora@prueba.com", "klk", "cosas sobre mi", "Ingeniero en sistema", "Habilidades", "Experiencia en el area", "Referencia de X persona", "Mis pasatiempos"));
                AInformacion.Add(new Informacion(03, "Chicharrado", null, "Jewyllon  sandoval", "gdf@dfgdf.com", "klk", 

I would like to know how I could, go through the array and identify which of the elements that I add belongs to ID 01 and print all its data in the console

In other words what you would want to do if you were using linq is

var item = (from i in AInformacion 
                        where i.ID == 01
                        select i
                          ).FirstOrDefault();

and then print it with a foreach , but I want to do it without using linq

This is the informacion class

 public Informacion(int iD,string puesto, int? aceptado, String nombre, String correo, String cedula, String about, String titulo, String skill, String experiencia, String referencia, String overtime /*, bool activo*/)
        {
            Puesto = puesto; // El puesto a cual quiere derigirse
            ID = iD; // ID numerico del curriculum
            Nombre = nombre; // Nombre y apellido del usuario
            Correo = correo; // Correo Electronico del usuario
            Cedula = cedula; // Cedula del usuario
            About = about; // informacion general del usuario
            Titulo = titulo; // titulos academicos del usuario (certificados, titulos, licencias)
            Skill = skill; // habilidades del usuario
            Experiencia = experiencia; // experiencias laborales del usuario
            Referencia = referencia; // referencias o contactos laborales del usuario
            Overtime = overtime; // pasatiempos/hobby del usuario
            Aceptado = aceptado;
        }
Jebus
  • 3
  • 2
  • 1
    What exactly is the problem you are having? How to loop throw the list? How to access the proeprties of an element? How to print an element to the console? – Klaus Gütter Feb 13 '23 at 14:35
  • Whether `AInformacion` of type `Array` or `Information[]` or `List` you can use `for` loop or Linq. What have you tried? – ChrisBD Feb 13 '23 at 14:36
  • https://stackoverflow.com/questions/12606061/iterate-through-listobject – Hossein Sabziani Feb 13 '23 at 14:36
  • 1
    Unrelated: [Remarks to ArrayList](https://learn.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=net-7.0#remarks) : _"**Important** - We don't recommend that you use the ArrayList class for new development. Instead, we recommend that you use the generic List class. [...]"_ – Fildor Feb 13 '23 at 14:39
  • @KlausGütter I am trying to print in the console the added element that has the name Jose Mora `AInformacion.Add(new Informacion(01, "Quedamo", null, "Jose Mora", "josemora@prueba.com", "047-1234567-1", "cosas sobre mi", "Ingeniero en sistema", "Habilidades", "Experiencia en el area", "Referencia de X persona", "Mis pasatiempos"));` , of all the items that have the arrangement, I only want to print that and all its data and I am not succeeding ,I tried this but it prints everything that the array list has and it doesn't work for me, I want to print something specific – Jebus Feb 13 '23 at 14:39
  • @KlausGütter This was what I tried `` static private void CExistente(ArrayList Ainfo) //Curriculim existentes { int fila_1 = 9; int iD = 1; foreach (Informacion p in Ainfo) { Console.SetCursorPosition(15, fila_1); Console.Write("#: " + iD.ToString()); Console.SetCursorPosition(15, fila_1+1); Console.Write("Nombre: " + p.getNombre()); ; Console.SetCursorPosition(15, fila_1+3); fila_1 += 4; iD++; }`` – Jebus Feb 13 '23 at 14:42
  • @KlausGütter The code works fine, but it prints all the elements of the ArrayList and I only want one of them to be printed and everything that goes with it, how can I condition this? – Jebus Feb 13 '23 at 14:45
  • @ChrisBD I would like to use linQ, it would be very easy with a select from and with a where, to then print the selection, but the project specifications prohibit me, I would like to know how else I can do the same – Jebus Feb 13 '23 at 14:48
  • 1
    Then use an `if` within the loop. – Klaus Gütter Feb 13 '23 at 14:59
  • I think "foreach" and "if" are more basic than linq, are you sure you don't know how to do with them? – shingo Feb 13 '23 at 15:03

1 Answers1

0
foreach (Informacion p in AInformacion)
{
    if(p?.ID != 1) continue;
    //Your print commands here
}

Remarks https://learn.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=net-7.0#remarks

Arvis
  • 8,273
  • 5
  • 33
  • 46