You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
14 Hrs
45 Min
16 Seg

Operadores LongCount y Count

17/26
Resources

Contributions 13

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

tambi茅n se puede hacer la condici贸n dentro del m茅todo count,
ella recibe como par谩metro una expresi贸n predicado

Hasta ahora en todas las clases estoy pausando el video para hacer el reto por mi cuenta y quitando una que no pude hacerlo el resto si lo he podido hacer. Muy recomendable que hag谩is lo mismo para asentar las bases

Utilizando una arrow function y con el predicate dentro del Count queda asi:

        public int NumberBooksBetween200And500Pages() =>
            booksCollection
            .Count(book => book.PageCount >= 200 && book.PageCount <= 500);

Es decir, viene siendo similar al .length en JavaScript. Se utiliza para obtener la longitud o cantidad de elementos en una colecci贸n.

Operadores LongCount y Count

Ambos operadores regresan la cantidad de registros que cumplen una condici贸n espec铆fica.

Utilice el filtro en el Count() y tambien cumple con el objetivo, una linea menos.

return librosCollection.Count(p => p.PageCount > 400 && p.PageCount < 500);

Pruebo hacerlo con una query expression:

        public long LibrosMas200Menos500paginas()
        {
            return (
                from l in librosCollection 
                where l.PageCount >= 200 && l.PageCount <= 500 
                select l)
                .LongCount();
        }

Fant谩stica Clase 鉂わ笍

Esta seria la funcion: ` public int NumberBooksBetween200And500Pages() =>` ` booksCollection` ` .Count(book => book.PageCount >= 200 && book.PageCount <= 500);`
Les comparto mis ejercicios utilizando Extension method y Query Expression utilizando ambos operadores: LongCount y Count. ```txt //Count() //Extension method return BooksCollections .Count(p => p.PageCount >= 200 & p.PageCount <= 500); //Query Expression var query = (from p in BooksCollections where p.PageCount >= 100 & p.PageCount <= 600 select p) .Count(); return query; //LongCount() //Extension method return BooksCollections .LongCount(p => p.PageCount > 0 & p.PageCount <= 1000); //Query Expression var query = (from p in BooksCollections where p.PageCount > 0 & p.PageCount <= 1000 select p).LongCount(); return query; ```
```c# public int GetCountBetweenPages(int minPages, int maxPages) { return librosCollection .Count(b => b.PageCount >= minPages && b.PageCount <= maxPages); } ```

Forma de hacerlo sin Where

Antes de ver el v铆deo - operador Count:

public int LibrosEntreXYPaginas(int limiteInferior, int limiteSuperior)
        {
            return librosCollection.Count(book => book.PageCount > limiteInferior && book.PageCount < limiteSuperior);
        }

uso:

//* Cantidad de libros entre 200 y 500 p谩ginas
        Console.WriteLine($"Cantidad de libros entre 200 y 500 p谩ginas: {queries.LibrosEntreXYPaginas(200, 500)}");