Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Linq Select Method
Use the Select method to modify the elements in an array.
The following is our string array.
string[] stationery = { "diary", "board", "pencil", "whiteboard" };
The Select method also specifies Lambda Expressions as shown below −
Example
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
string[] stationery = { "diary", "board", "pencil", "whiteboard" };
var res = stationery.AsQueryable().Select((item, index) => new { result = item.Substring(0, index + 4) });
foreach (var str in res) {
Console.WriteLine("{0}", str);
}
}
}
Output
{ result = diar }
{ result = board }
{ result = pencil }
{ result = whitebo } Advertisements
