In C#, as in many programming languages, characters are stored internally as the integral value of their ASCII code rather than as short string objects, meaning that one can perform arithmetic directly on char-typed variables without having to cast or parse them before hand. This feature significantly sped up my solution to Project Euler problem 22, which asks:

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.

What is the total of all the name scores in the file?

The text file contains 5,163 comma-separated names written on a single line, each written in all caps and enclosed in double quotation marks. I think this was purely a programming question: I can't for the life of me think of any elegant, mathematical solution to this problem, so I split the line of comma-separated names, alphabetically sorted the resulting list, went through said list, calculated the score for each name, and added it to a running total. A google search revealed that this is exactly what everyone else did, seeming to confirm my suspicion that this problem is purely a question of coding, not constructing an algorithm.

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem022
{
    class Program
    {
        static void Main(string[] args)
        {
            string fileName = @"C:\Users\jonny\Desktop\names.txt";
            StreamReader textReader = new StreamReader(fileName);
            string[] names = textReader.ReadLine().Split(',');
            int nameCharProduct = 0;
            long runningTotalOfProducts = 0;
            Array.Sort(names);

            for (int i = 0; i < names.Length; i++)
            {
                names[i] = names[i].Replace("\"", "");
                for (int j = 0; j < names[i].Length; j++)
                    nameCharProduct += names[i][j] - 64; // The ASCII value of 'A' is 65
                nameCharProduct *= i + 1;
                runningTotalOfProducts += nameCharProduct;
                nameCharProduct = 0;
            }

            Console.WriteLine(runningTotalOfProducts);
        }
    }
}