Convert linq query to string array - C#

arrays, c#, casting, linq, string

Solution

I prefer the lambda style, and you really ought to be disposing your data context.

private string[] WordList()
{
    using (DataContext db = new DataContext())
    {
       return db.Words.Select( x => x.Word ).OrderBy( x => x ).ToArray();
    }
}

Problem

What is the most efficient way of converting a single column linq query to a string array? ``` private string[] WordList() { DataContext db = new DataContext(); var list = from x in db.Words orderby x.Word ascending select new { x.Word }; // return string array here } ``` Note - x.Word is a string

Original source