Sort strings in a file in CSharp

Description

The following code shows how to sort strings in a file.

Example


    /*  www . j av  a  2  s.  c o m*/


using System;
using System.IO;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Xml.Linq;

    class Program
    {
        static void Main(string[] args)
        {

            List<string> strs = new List<string>();
            using( StreamReader sReader = new StreamReader("Main.cs"))
            {
              string str;
              str = sReader.ReadLine();
              while (str != null)
              {
                strs.Add(str);
              }
            }
            IEnumerable<string> i = from name in strs orderby name descending select name;
            foreach (string nam in i)
            {
              Console.WriteLine(nam);
            }
        }
    }




















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ