Skip to main content
2 of 3
Forgot to put in alphabetical order before determining the score. Also forgot to split the lines by comma.

Here's a way to do it in one line of Linq code:

int score = System.IO.File.ReadAllLines(ConfigurationManager.AppSettings["LocationOfNamesFile"])
    .SelectMany(s => s.Split(','))
    .OrderBy(b => b)
    .Select((s, i) => new { 
        Index = i + 1, 
        Score = s.Sum(ch => (int)(char.ToUpper(ch) - 'A' + 1))
    .Sum(s => s.Index * s.Score);

This will throw an exception if the file doesn't exist, but your original code does this as well.