Linq Select Lambda Example

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
					
public class Program
{
	public static void Main()
	{
		List<String> trees = new List<String>{ "Oak", "Birch", "Beech", "Elm", "Hazel", "Maple" };
		//The below select stament transforms each element in tree into its first character.
		IEnumerable<String> initials = trees.Select(tree => tree.Substring(0, 1));
		foreach (String initial in initials) {
			System.Console.WriteLine(initial);
		}
	}
}
;