Apply function to all list elements using VB.NET

2

Is there any function / module for an object of type List in VB.NET that is similar to array_map() of PHP?

The idea is to create a new variable with elements that satisfy a given condition.

I have a list of objects of type FtpListItem , and I only need the files where the modification date is greater than the UltimoHorario variable. Function example:

Function ValidarArquivo(arquivo As FtpListItem)
    If arquivo.Modified.Compare(UltimoHorario) > 0 Then
        Return True
    End If
End Function
    
asked by anonymous 10.07.2015 / 20:43

1 answer

3

LINQ is a query language to work with any type of data collection, from arrays to collections that map to database.

You have not posted something that is easy to identify what you really want but essentially it should be this:

arquivosFiltrados = listaArquivos.Where(x => x.Modified.Compare(UltimoHorario) > 0)

Or if you prefer to use your function:

arquivosFiltrados = listaArquivos.Where(x => ValidarArquivo(x))

Just remembering that this list must be of type IEnumarable<FtpListItem> to work. And its function would need to be modified to have a return on all possible paths, ie it should have a Return False if the individual file does not meet the criteria.

If you have other details I'd better answer. I'm assuming your comparison is being made the way you want it.

Look for a good study in LINQ, it's very useful for a lot of things, either in the form presented or in the form of query language according to the documentation I've listed above.

    
10.07.2015 / 21:44