Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8436849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:17:39+00:00 2026-06-10T07:17:39+00:00

I’m pushing the limits of my knowledge in c# and linq here, so please

  • 0

I’m pushing the limits of my knowledge in c# and linq here, so please bear with me if I’m completely off with my example or understanding of linq, c#, generic types, lambda expressions,design patterns, etc.

I have a class that holds two collections, one is the collection to be filtered: IEnumberable<InstagramUser> and the second is the collection of expressions to filter on: IEnumerable<IInstagramFilter>.

public class InstagramDisplay {

    public IEnumerable<InstagramUser> instagramUsers;
    public IEnumerable<IInstagramFilter> instagramFilters; 

    public InstagramDisplay() {
        instagramUsers = new List<InstagramUser>();
        instagramFilters = new List<IInstagramFilter>();
    }

    public IEnumerable<InstagramUser> display() {
        instagramFilters.ToList().ForEach(x => instagramUsers.Where(x.filter(instagramUsers)));
        return instagramFilters;
    }
}

public interface IInstagramFilter {
    Expression<Func<T, bool>> filter<T>(IQueryable<T> source); 
}

I would have classes extend IInstagramFilter. Each IInstagramFilter class would have a property (or function – not sure what’s best) that would return the lambda expression that would be applied to IEnumerable<InstagramUser> in the display() method.

public class UserFilter : IInstagramFilter {
    public Expression<Func<T, bool>> filter<T>(IQueryable<T> source) {
        //return some expression - but how?
    }
}

I’m struggling to understand a few things:

  1. How to set the expression for each IInstagramFilter class and then call it in the display() method?

  2. Each IInstagramFilter class would have a lambda that would be used to filter IEnumerable<InstagramUser> but since the Filter class has no knowledge of IEnumerable<InstagramUser> how would I create the appropriate lambda in the first place?

  3. I think this roughly follows the Decorator Pattern but perhaps there’s a better design all together that I’m not aware of.

UPDATED CODE

Based on Olivier’s answer this is what I have now. On the return for display() I’m getting the error when using .Where(filter)

The type arguments for method ‘System.Linq.Enumerable.Where<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)‘ cannot be inferred from the usage. Try specifying the type arguments explicitly.

public class InstagramDisplay {

    public IEnumerable<InstagramUser> instagramUsers;
    public List<Expression<Func<InstagramUser, bool>>> instagramFilters; 

    public InstagramDisplay() {
        instagramUsers = new List<InstagramUser>();
        instagramFilters = new List<Expression<Func<InstagramUser, bool>>>();
    }

    public void addFilter(Expression<Func<InstagramUser, bool>> filter) {
        instagramFilters.Add(filter);
    }

    public IEnumerable<InstagramUser> display() {
        return instagramFilters.SelectMany(filter => instagramUsers.Where(filter)).Distinct(); //error on this line
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:17:40+00:00Added an answer on June 10, 2026 at 7:17 am

    You have to decide whether you want to perfom some action or whether you want to return something. List<T>.ForEach() performs an action on each item but has a void return type and does not return anything.

    This IInstagramFilter interface seems superfluous to me. You can declare a filter list like this

    var userFilters = new List<Expression<Func<InstagramUser, bool>>>();
    userFilters.Add(u => u.Name.StartsWith("A"));
    userFilters.Add(u => u.Score >= 100);
    

    If you have a source of users you can do something like this to all users returned by all filters

    IQueryable<InstagramUser> usersSource = ...; 
    // Or IEnumerable<InstagramUser> for LINQ to objects
    // if you drop the Expression<> part.
    
    var users = userFilters.SelectMany(f => usersSource.Where(f));
    

    SelectMany flattens the nested enumerations. The example returns all users whos name starts with “A” or who have a score >= 100. This might return a user twice, therfore I would suggest to append a .Distinct()

    var users = userFilters
        .SelectMany(f => usersSource.Where(f))
        .Distinct();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.