I am working on a program that sorts dictionary words by length. The current code outputs the results. I am having trouble saving the results as a text file.
Current Code
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
// Initialize a List of strings.
string filePath = "text.txt";
List<string> linesList = new List<string>();
string[] fileContent = System.IO.File.ReadAllLines(filePath);
linesList.AddRange(fileContent);
// Send the List to the method.
foreach (string s in SortByLength(linesList))
{
Console.WriteLine(s);
}
System.IO.File.WriteAllLines("solution.txt",sorted);
}
static IEnumerable<string> SortByLength(IEnumerable<string> e)
{
// Use LINQ to sort the array received and return a copy.
var sorted = from s in e
orderby s.Length ascending
select s;
return sorted;
}
}