Filter the string by starting character in CSharp

Description

The following code shows how to filter the string by starting character.

Example


using System;/* ww w  . j a  v  a  2  s. com*/
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        string[] presidents = {"A", "Ar", "B", "Bu", "C", "Cleveland"};

        IEnumerable<string> sequence = presidents.Where(p => p.StartsWith("C"));

        foreach (string s in sequence)
            Console.WriteLine("{0}", s);

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ