Input: | IEnumerable<TSource> |
Lamdbda expression: | TSource => TResult or (TSource,int) => TResult |
Query syntax: | select projectionExpression |
Select
returns the same number of elements as the input.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] names = { "Java", "C#", "Javascript", "SQL", "Oracle", "Python", "C++", "C", "HTML", "CSS" };
IEnumerable<string> query = from n in names select n.ToLower();
foreach(String s in query){
Console.WriteLine(s);
}
}
}
The output:
java
c#
javascript
sql
oracle
python
c++
c
html
css
The select operator can accept an integer argument as an indexer.
This works only with local queries:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] names = { "Java", "C#", "Javascript", "SQL", "Oracle", "Python", "C++", "C", "HTML", "CSS" };
IEnumerable<string> query = names.Select((s, i) => i + "=" + s);
foreach(String s in query){
Console.WriteLine(s);
}
}
}
The output:
0=Java
1=C#
2=Javascript
3=SQL
4=Oracle
5=Python
6=C++
7=C
8=HTML
9=CSS
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |