Select string length from string array in CSharp

Description

The following code shows how to select string length from string array.

Example


using System;// w  ww.  j av a  2 s .  co  m
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        string[] presidents = {"A", "Ar", "Buc", "Bush", "Carte", "Clevel"};

        var nameObjs = presidents.Select(p => new { p, p.Length });

        foreach (var item in nameObjs)
            Console.WriteLine(item);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ