Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It might help to look at the definition of this method in C#, from the MSDN article you refer to:</p> <pre><code>public static IEnumerable&lt;TResult&gt; Select&lt;TSource, TResult&gt;( this IEnumerable&lt;TSource&gt; source, Func&lt;TSource, TResult&gt; selector ) </code></pre> <p>The <code>&lt;</code>angle brackets<code>&gt;</code> denote the type parameters for this generic method, and we can start to explore the purpose of the method simply by looking at what the type parameters are doing.</p> <p>We begin by looking at the name of the generic method:</p> <pre><code>Select&lt;TSource, TResult&gt; </code></pre> <p>This tells us that the method called <code>Select</code> deals with two different types:</p> <ul> <li>The type <code>TSource</code>; and</li> <li>The type <code>TResult</code></li> </ul> <p>Let's look at the parameters:</p> <ol> <li>The first parameter is <code>IEnumerable&lt;TSource&gt; source</code> — a source, providing a <code>TSource</code> enumeration.</li> <li>The second parameter is <code>Func&lt;TSource, TResult&gt; selector</code> — a selector function that takes a <code>TSource</code> and turns it into a <code>TResult</code>. (This can be verified by exploring the definition of <code>Func</code>)</li> </ol> <p>Then we look at its return value:</p> <pre><code>IEnumerable&lt;TResult&gt; </code></pre> <p>We now know this method will return a <code>TResult</code> enumeration.</p> <p><strong>To summarise</strong>, we have a function that takes an enumeration of <code>TSource</code>, and a selector function that takes individual <code>TSource</code> items and returns <code>TResult</code> items, and then the whole select function returns an enumeration of <code>TResult</code>.</p> <p><strong>An example:</strong></p> <p>To put this into concrete terms, lets say that <code>TSource</code> is of type <code>Person</code> (a class representing a person, with a name, age, gender, etc), and <code>TResult</code> is of type <code>String</code> (representing the person's name). We're going to give the <code>Select</code> function a list of <code>Person</code>s, and a function that, given a <code>Person</code> will select just their name. As the output of calling this <code>Select</code> function, we will get a list of <code>String</code>s containing just the names of the people.</p> <p><strong>Aside:</strong></p> <p>The last piece of the puzzle from the original method signature, at the top, is the <code>this</code> keyword before the first parameter. This is part of the syntax for defining <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" rel="noreferrer">Extension Methods</a>, and all it essentially means is that instead of calling the static Select method (passing in your source enumeration, and selector function) you can just invoke the Select method directly on your enumeration, just as if it had a <code>Select</code> method (and pass in only one parameter — the selector function).</p> <p>I hope this makes it clearer for you?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload