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 6959695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:18:20+00:00 2026-05-27T15:18:20+00:00

having some doubts with LINQ queries over objects… I have this filter descriptions which

  • 0

having some doubts with LINQ queries over objects…

I have this filter descriptions which I want to keep private, and at given checkpoints in the code, I set some flags active. At the end of processing, I want to filter the active flags.

If any flags are active, I want to write them to the console. (I want all flagged checkpoints in one string so I can perhaps change the code to throw an exception instead later on).

This is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;

namespace checkpoints
{
    public class Program
    {
        public static void Main(string[] args)
        {            
            var filters = new Filters().FilterList;

            filters[0].flag = true;
            filters[2].flag = true;

            var query = filters.Where(f => f.flag).Select(f => f.desc); 
            Console.WriteLine("Filter points active: ");
            string fpoints = System.String.Empty;

            foreach(string fp in query)
                { fpoints = fpoints + fp + System.Environment.NewLine; }

            Console.WriteLine(fpoints);
        }
    }
    public class Filters
    {        
        public List<Filter> FilterList = new List<Filter>{};

        public Filters()
        {
           foreach(var def in Filters.def_desc)               
               { this.FilterList.Add(new Filter(false, def)); }
        }

        private readonly static string[] def_desc = new string[3]
        { "Filter AX2123: Failed file write.", 
          "Filter XVB231: Failed table load.", 
          "Filter FZD358: Transaction halted." };

        public class Filter
        {
            public bool flag;
            public readonly string desc;       

            public Filter(bool flag, string desc)
            {
                this.flag = flag;
                this.desc = desc;
            }
        }            

    }
}

It works. My issue is with the need to run a for each over the LINQ query results (which is a IEnumerable<Filter> I guess) in order to extract the strings. If I already run a query (i.e., went all over the code) why do I need to “run again”? Looks like it scales terrible and is not very elegant… Any thoughts?

  • 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-05-27T15:18:20+00:00Added an answer on May 27, 2026 at 3:18 pm
    string fpoint=query.Aggregate((c, c1) => c + System.Environment.NewLine+ c1 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some doubts regarding service hosting in WCF. I want to host a
I'm having some doubts on how to set up my SVN stuff. First my
I'm having some trouble with this statement, owing no doubt to my ignorance of
After another question about iterators I'm having some doubts about custom containers. In my
Thanks for taking time to read my questions. I am having some basic doubts
I am in process to create a Database connection class but having some doubts
I'm having some hard trouble finding the answer for this Is there anyway to
i'm playing around with sockets, and I'm having some doubts about using blocking sockets
Hey guys, i'm having some trouble with this: In the object consumer i need
I'm having a small doubt in shell Scripting I have a program (a.out) which

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.