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

  • SEARCH
  • Home
  • 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 7864781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:53:17+00:00 2026-06-02T23:53:17+00:00

I am wondering if there would be any LINQ/Lambda expression solution for the problem

  • 0

I am wondering if there would be any LINQ/Lambda expression solution for the problem below.

I have 2 generic lists

List 1

public class Data
{
  public string ID { get; set;}
  public string Package { get; set;}
}

List<Data> listData = new List<Data>();

Data data1 =  new Data { ID = "1", Package = "Test" };
Data data2 =  new Data { ID = "2", Package = "Test2" };
Data data3 =  new Data { ID = "3", Package = "Test2" };
Data data4 =  new Data { ID = "4", Package = "Test4" };

listData.Add(data1);
listData.Add(data2);
listData.Add(data3);
listData.Add(data4);

List 2

List<int> listFilter =  List<int>();

listFilter.Add(1);
listFilter.Add(0);
listFilter.Add(0);
listFilter.Add(1);

I would like to filter “listData” based on the true (1) criteria from “listFilter”. For the above example, I must be able to pull data1 and data4 into a new list.

At the moment, I am using a for loop to achieve this as below.

List<Data> listResult =  new List<Data>();
for(int index=0; index<listData.Count; index++)
{
    if(listFilter[index]==1)
    {
       listResult.Add(listData[index]);
    }

}

I would appreciate if someone could show me to use LINQ or Lambda expression to achieve this.

Thanks

Balan

  • 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-02T23:53:19+00:00Added an answer on June 2, 2026 at 11:53 pm
    var results = listData.Where((item, index) => listFilter[index] == 1);
    

    Note that this will fail if listData is longer than listFilter, same as your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am wondering if there would be any security flaw in this approach. I am
Wondering if there is any way to get the lambda expressions that result from
I was wondering if there would be any confident approach for use in catch
I'm wondering if there would be any merit in trying to code a strlen
Is there any elegant way of splitting a list/dict into two lists/dicts in python,
I was wondering if there is any Python library out there which would allow
I am just wondering if there would be any loss of speed or efficiency
Reading through this question on multi-threaded javascript, I was wondering if there would be
I'm wondering what good ways there would be make assertions about synchronization or something
I was wondering if there was a software that would generate UML class diagrams

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.