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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:25:34+00:00 2026-05-20T17:25:34+00:00

I am fairly new to LINQ. I am looking at this code, and not

  • 0

I am fairly new to LINQ. I am looking at this code, and not sure if I understand this properly. I realize that it is an extension and generic method, but what is predicate(item, index) performing (lets say i pass in an array of ints when calling this method)?

I know that predicate is a delegate, but maybe I just don’t know how delegation works, someone has any good example/explanation they’d like to give. Also, what is yield keyword, is it just used in linq stuff?

private static IEnumerable<TSource> WhereImpl<TSource>(
    this IEnumerable<TSource> source,
    Func<TSource, int, bool> predicate)
{
    int index = 0;
    foreach (TSource item in source)
    {
        if (predicate(item, index))
        {
            yield return item;
        }
        index++;
    }
}

I am trying to follow Reimplementing LINQ to Objects: Part 2 – “Where” from Skeet’s blog.

  • 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-20T17:25:35+00:00Added an answer on May 20, 2026 at 5:25 pm
    predicate(item, index)
    

    is defined to be of type

    Func<TSource, int, bool>
    

    that means a method that has parameters of TSource and int and returns a bool – a predicate.

    An example for TSource = string could be (totally made up):

    bool IsLengthLargerThan(string s, int length)
    {
      return s.Length > length;
    }
    

    Also, what is yield keyword, is it
    just used in linq stuff?

    yield is specific to iterator blocks – this has been around before LINQ. It basically works like a state machine – yield return item; will return item to the caller and suspend execution, but once you request the next item, execution will resume on the next line. It’s easiest to see how it works if you step through it with a debugger.

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

Sidebar

Related Questions

I'm fairly new to linq and wanted to delve in a bit deeper by
I'm fairly new to LINQ in general but I've managed to figure things out
I am fairly new to Linq To SQL but trying to run what should
I'm fairly new to LINQ to SQL, so I could be missing something basic
Fairly new to mysql, and I am lost at the moment. This is my
Im fairly new to android dev and I want to build an app that
Im fairly new to developing in Drupal, i am using the 7.x code. I
Being fairly new to JavaScript, I'm unable to discern when to use each of
I'm still fairly new to T-SQL and SQL 2005. I need to import a
I'm fairly new to ASP.NET and trying to learn how things are done. I

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.