Project Euler 42 - finding triangle number V2 This is my revised solution to Problem 42 from Project Euler, based on suggestions in this original post Project Euler 42 - Finding triangle numbers

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;
using System.Diagnostics;

namespace ProjectEuler
{
    class p42trianglenumber
    {
        // p42. tn = ½n(n+1)
        // A=1, B=2, etc. case insensitive. 
        public static void NotMain()
        {                   
            var sw = new Stopwatch();
            sw.Start();
            int numberTriangleWords = 0;            
            string[] words = ReturnStringArray("p042_words.txt");
            int[] triangleNumbers = BuildTriangleNumber();

            foreach (string word in words)
            {
                var score = GetScore(word);                

                if (triangleNumbers.Contains(score))
                {
                    numberTriangleWords++;
                }
            }
            sw.Stop();
            Console.WriteLine(numberTriangleWords + Environment.NewLine + sw.ElapsedMilliseconds.ToString() + "ms");
            Console.ReadLine();
        }

        private static string[] ReturnStringArray(string fileLocation)
        {
            StreamReader sr = new StreamReader(fileLocation);
            string[] words = sr.ReadLine().Split(',');
            return words;
        }

        private static bool IsWordTriangleNumber(int wordVal, int[] triangleNumbers)
        {
            return (triangleNumbers.Contains(wordVal));            
        }

        private static int[] BuildTriangleNumber()
        {
            int triangleNumberValue = 0;
            int[] triangleNumbers = new int[50];

            for (int i = 0; i &lt; 50; i++)
            {
                if (i == 0)
                    triangleNumbers[i] = triangleNumberValue;
                else
                {
                    triangleNumberValue += i;
                    triangleNumbers[i] = triangleNumberValue;
                }
            }
            return triangleNumbers;
        }       

        private static int GetScore(string word)
        {
            var total = 0;
            foreach (var letter in word)
            {
                total += GetScore(letter);
            }
            return total;
        }

        private static int GetScore(char letter)
        {
            var start = char.IsLower(letter) ? 'a' : 'A';
            var score = (int)letter - (int)start + 1;
            if (score &lt; 0 || score &gt; 26) return 0;
            return score;
        }
    }
}
Possible problem  


private static string[] ReturnStringArray(string fileLocation)
{
    StreamReader sr = new StreamReader(fileLocation);
    string[] words = sr.ReadLine().Split(',');
    return words;
}  



With this method you don't read the whole file but only the first line in the textfile. Usually project Euler problem don't involve only one line of anything but rather some 10k of something.



In the first 5 lines of code I would change 3 variables/method names  


        int numberTriangleWords = 0;            
        string[] words = ReturnStringArray("p042_words.txt");
        int[] triangleNumbers = BuildTriangleNumber();  



The problem is about getting the number of triangle words.   

int numberOfTriangleWords = 0  


You are reading a text file as words.  

string[] words = ReadFileAsWords("p042_words.txt");  


You are creating / building an array of numbers  

int[] triangleNumbers = BuildTriangleNumbers();  


This is just nitpicking on the naming, but naming is a very important part of writing good readable and maintainable code.  



This method  


    private static bool IsWordTriangleNumber(int wordVal, int[] triangleNumbers)
    {
        return (triangleNumbers.Contains(wordVal));            
    }  



isn't used anywhere. You should delete it.  




    private static int[] BuildTriangleNumber()
    {
        int triangleNumberValue = 0;
        int[] triangleNumbers = new int[50];

        for (int i = 0; i &lt; 50; i++)
        {
            if (i == 0)
                triangleNumbers[i] = triangleNumberValue;
            else
            {
                triangleNumberValue += i;
                triangleNumbers[i] = triangleNumberValue;
            }
        }
        return triangleNumbers;
    }  



Because triangleNumbers is an array of the int struct, the items are initialized using default(T) which for an int is 0. Therefor if you just let the loop start at 1 you wouldn't need the check if (i == 0) at all which would also remove the braceless single line statement after the if.
I would like to encourage you to always use braces {} to make your code less error prone. Saving a few milliseconds by omitting them can lead to problems later on which patching can take a lot of time.  

    private static int[] BuildTriangleNumber()
    {
        int triangleNumberValue = 0;
        int[] triangleNumbers = new int[50];

        for (int i = 1; i &lt; 50; i++)
        {
            triangleNumberValue += i;
            triangleNumbers[i] = triangleNumberValue;
        }
        return triangleNumbers;
    }  




I like the overloading of the GetScore() method, but the GetScore(char) method can be improved.  


    private static int GetScore(char letter)
    {
        var start = char.IsLower(letter) ? 'a' : 'A';
        var score = (int)letter - (int)start + 1;
        if (score &lt; 0 || score &gt; 26) return 0;
        return score;
    }  



There is no need to first assign a or A to start and then later on cast it to an int. The int value of a == 97 and of A == 65. So using these values should speed the whole thing up.  

Edit Based on @Caridorc's comment
I have extracted these values to private static reaonly variables using a naming scheme which isn't legit by the meaning of the c# naming guidelines but looks better with the underscore in it.

    private static int ASCIIValue_a = 97;
    private static int ASCIIValue_A = 65;
    private static int GetScore(char letter)
    {
        var start = char.IsLower(letter) ? ASCIIValue_a : ASCIIValue_A;
        var score = (int)letter - start + 1;
        if (score &lt; 0 || score &gt; 26) return 0;
        return score;
    }