Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
C# Using array.Where in Arraylist

I have sets of codes in C# with array and I need to split the array into smaller size array. I have no errors when declaring the array with :

List<int> array = new List<int>();

However, the code execution prompts out error at the array.Where when I declare as :

var array = new ArrayList();

Is there any way I can use array.Where in array list? Below is my code :

List<int> array = new List<int>();

for (int i = 0; i <=20; i++){
  if (unitIsPresent) 
  {
    array.add(1);
  } 
  else
  {
    array.add(0)
  }
}

devidedArray = array.Where((e, i) => i >= 5 && i < 10).ToArray();
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Array List is a non generic collection type so it's good to store items in array where you don't consider the items types. So for this reason you can't use Linq methods that are used for generics collections like Where. My recommendation is use a List and convert it to Array with the Linq method provided.this way is very fast.

over 4 years ago · Santiago Trujillo Denunciar

0

If you really want to use an ArrayList (really? why?), you can use OfType<int>() to change the IEnumerable to an IEnumerable<int>.

var devidedArray = array.OfType<int>().Where((e, i) => i >= 5 && i < 10).ToArray();

Alternatively you could use Cast<int>():

var devidedArray = array.Cast<int>().Where((e, i) => i >= 5 && i < 10).ToArray();

The difference between the two is that OfType() will silently ignore objects that cannot be cast to int while Cast() will fail with an InvalidCastException.

over 4 years ago · Santiago Trujillo Denunciar

0

https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=net-5.0

look microsoft doc.

We don't recommend that you use the ArrayList class for new development. Instead, we recommend that you use the generic List class. ...

just use List<T> to replace ArrayList.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda