[Root] / Xceed Data Manipulation Components for .NET / [Root] / Basic Concepts / [Root] / Filters / AndFilter

In This Topic
    AndFilter
    In This Topic

    The AndFilter class serves the same purpose as a logical-and operator. It states that the items must match all the filters regrouped within the AndFilter class in order to be processed.

    Demonstration

    Process all the files in folder that contain the txt extension and that are between 5k and 10k size.

    C#
    Copy Code
    SizeFilter filter = new SizeFilter();
    
    filter.MaxSize = 10 * 1024;
    filter.MinSize = 5 * 1024; 
    
    AbstractFile[] files = myFolder.GetFiles( true,
                                              new AndFilter( new NameFilter( "*.txt" ), 
                                              filter ) );
    VB.NET
    Copy Code
    Dim filter As New SizeFilter()
    
    filter.MaxSize = 10 * 1024
    filter.MinSize = 5 * 1024
    
    Dim files As AbstractFile() = myFolder.GetFiles( True, _
                                                     New AndFilter( New NameFilter( "*.txt" ), _
                                                     filter ) )

    Since the AndFilter is used by default when combining multiple filters, it is not necessary to create an instance of the AndFilter class. Therefore, we can omit the creation of the class. We can also omit creating a NameFilter class since we are using a basic string filter and the NameFilter class is constructed underneath.

    C#
    Copy Code
    SizeFilter filter = new SizeFilter();
    
    filter.MaxSize = 10 * 1024;
    filter.MinSize = 5 * 1024; 
    
    AbstractFile[] files = myFolder.GetFiles( true, "*.txt", filter );
    VB.NET
    Copy Code
    Dim filter As New SizeFilter()
    
    filter.MaxSize = 10 * 1024
    filter.MinSize = 5 * 1024 
    
    Dim files As AbstractFile() = myFolder.GetFiles( True, "*.txt", filter )