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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:17:02+00:00 2026-05-15T14:17:02+00:00

can someone please help me turn this nested structure into a single LINQ statement?

  • 0

can someone please help me turn this nested structure into a single LINQ statement?

        EventLog[] logs = EventLog.GetEventLogs();
        for (int i = 0; i < logs.Length; i++)
        {
            if (logs[i].LogDisplayName.Equals("AAA"))
            {
                for (int j = 0; j < logs[i].Entries.Count; j++)
                {
                    if (logs[i].Entries[j].Source.Equals("BBB"))
                    {
                        remoteAccessLogs.Add(logs[i].Entries[j]);
                    }
                }
            }
        }
  • 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-15T14:17:03+00:00Added an answer on May 15, 2026 at 2:17 pm

    Nested loops usually end up with multiple “from” clauses (which are converted into calls to SelectMany by the compiler):

    var remoteAccessLogs = from log in EventLogs.GetEventLogs()
                           where log.LogDisplayName == "AAA"
                           from entry in log.Entries
                           where entry.Source == "BBB"
                           select entry;
    

    (That’s assuming that remoteAccessLogs is empty before this call, and that you’re happy iterating over it directly – you can call ToList() if you want a List<T>.)

    Here’s the dot notation form:

    var remoteAccessLogs = EventLogs.GetEventLogs()
                                    .Where(log => log.LogDisplayName == "AAA")
                                    .SelectMany(log => log.Entries)
                                    .Where(entry => entry.Source == "BBB");
    

    Or for a list:

    var remoteAccessLogs = EventLogs.GetEventLogs()
                                    .Where(log => log.LogDisplayName == "AAA")
                                    .SelectMany(log => log.Entries)
                                    .Where(entry => entry.Source == "BBB")
                                    .ToList();
    

    Note that I’ve used the overloaded == for string as I find it easier to read than calling the Equals method. Either will work though.

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

Sidebar

Related Questions

Can someone please help to convert this to linq? SELECT x.contentobjectid, Min(x.city) as city,
Can someone please help convert the following into LINQ To SQL query? select *
can someone please help me. why does this return an error: Dim stuff As
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Could someone please help explain why I can't get this to work? I properly
Can someone please help me on this find specific record Edit through MS access
Can someone please help me with this preg_match if (preg_match('~[^A-Za-z0-9_\./\]~', $filepath)) // Show Error
can someone please help me with this javascript:void(null) I found it used in link
Can someone please help me simpling this redundant piece of code? if (isset($to) ===
I wonder whether someone can help me please. I've put together this page, 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.