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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:03:24+00:00 2026-05-16T03:03:24+00:00

Learning a bit about Linq. I have the following code: (Please excuse the pathetic

  • 0

Learning a bit about Linq.
I have the following code:

(Please excuse the pathetic size of the data set)

class Program
{
    static void Main(string[] args)
    {
        var employees = new List<Employee>
                            {
                                new Employee
                                    {
                                        Name = "Bill Bailey",
                                        EmployeeCode = 12345,
                                        Department = "Comedy Lab",
                                        DateOfBirth = DateTime.Parse("13/01/1964"),
                                        CurrentEmployee = true
                                    },
                                new Employee
                                    {
                                        Name = "Boris Johnson",
                                        EmployeeCode = 56789,
                                        Department = "Cycling Dept.",
                                        DateOfBirth = DateTime.Parse("19/06/1964"),
                                        CurrentEmployee = true
                                    },
                                new Employee
                                    {
                                        Name = "Bruce Forsyth",
                                        EmployeeCode = 5,
                                        Department = "Comedy Lab",
                                        DateOfBirth = DateTime.Parse("22/03/1928"),
                                        CurrentEmployee = false
                                    },
                                new Employee
                                    {
                                        Name = "Gordon Brown",
                                        EmployeeCode = 666,
                                        Department = "Backbenches",
                                        DateOfBirth = DateTime.Parse("20/02/1951"),
                                        CurrentEmployee = false
                                    },
                                new Employee
                                    {
                                        Name = "Russell Howard",
                                        EmployeeCode = 46576,
                                        Department = "Comedy Lab",
                                        DateOfBirth = DateTime.Parse("23/03/1980"),
                                        CurrentEmployee = false
                                    }
                            };

        Func<Employee, bool> oapCalculator = (employee => employee.DateOfBirth.AddYears(65) < DateTime.Now);

        var oaps1 = employees.Where(oapCalculator);
        var oaps2 = (from employee in employees
                     where oapCalculator(employee)
                     select employee);

        oaps1.ToList().ForEach(employee => Console.WriteLine(employee.Name));
        oaps2.ToList().ForEach(employee => Console.WriteLine(employee.Name));

        Console.ReadLine();
    }

    class Employee
    {
        public string Name { get; set; }
        public int EmployeeCode { get; set; }
        public string Department { get; set; }
        public DateTime DateOfBirth { get; set; }
        public bool CurrentEmployee { get; set; }
    }
}

I have a few questions:

As far as I can tell, both of the featured Linq queries are doing the same thing (black magic may be afoot).

  1. Would they both be compiled down to the same IL?
  2. If not, why, and which would be the most efficient given a sizable amount of data?
  3. What is the best way to monitor Linq query efficiency? Performance timers or something built-in?
  4. Is the lambda expression the preferred method, as it is the most concise?
  5. In a department of lambda fearing luddites, is it worth taking the plunge and teaching ’em up or using the SQL-esque syntax?

Thanks

  • 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-16T03:03:25+00:00Added an answer on May 16, 2026 at 3:03 am

    Re

    var oaps1 = employees.Where(oapCalculator);
    

    vs

    var oaps2 = (from employee in employees
                 where oapCalculator(employee)
                 select employee);
    

    There is a slight difference, in particular around the where oapCalculator(employee). The second query is mapped to:

    var oaps2 = employees.Where(employee => oapCalculator(employee));
    

    so this is an extra layer of delegate, and will also incur the (small) overhead of a capture-class due to the closure over the variable oapCalculator, and a dereference of this per iteration. But otherwise they are the same. In particular, the Select is trivially removed (in accordance with the spec).

    In general, use whichever is clearest in any scenario. In this case, either seems fine, but you will find it easier to use .Where etc if you are regularly dealing in scenarios that involving delegates or Expressions.

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

Sidebar

Related Questions

I'm currently learning a bit more about Linq-To-Entities - particularly at the moment about
I'm about to start learning Ruby and would like a bit of reading material
I'm learning a bit about function programming, and I'm wondering: 1) If my ForEach
I am still learning quite a bit about programming so this may be an
Learning a little about T-SQL, and thought an interesting exercise would be to generate
I'm learning about table design in SQL and I'm wonder how to create a
I remember first learning about vectors in the STL and after some time, I
I'm just learning LINQ and in particular LINQ to XML, and I've written up
I've been messing about with the Ordnance Survey Code-Point Open dataset of UK postcodes/co-ordinates.
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring

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.