Select substring from a string array in CSharp

Description

The following code shows how to select substring from a string array.

Example


     /*from   w  w w . jav a  2s  . com*/

using System;
using System.Collections;
using System.Linq;
using System.ComponentModel;

    class MainClass
    {
        static void Main()
        {
            ArrayList list = new ArrayList { "First", "Second", "Third" };
            var strings = from string entry in list
                          select entry.Substring(0, 3);


            foreach (string start in strings)
            {
                Console.WriteLine(start);
            }
        }
    }

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ