So this question is prompted by two things.I found some code in our source control doing this sort of things.These SO questions: https://stackoverflow.com/questions/297213/translate-an-index-into-an-excel-column-namehttps://stackoverflow.com/questions/837155/fastest-function-to-generate-excel-column-letters-in-c-sharphttps://stackoverflow.com/questions/4075656/how-to-get-continuous-characters-in-c/4077835#4077835https://stackoverflow.com/questions/1011732/iterating-through-the-alphabet-c-sharp-a-cazSo when I thought about this problem this popped into my head almost immediately. class Util{    private static string[] alphabetArray = { string.Empty, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z };    public static IEnumerable<string> alphaList = alphabetArray.Cast<string>();    public static string IntToAA(int value)    {        while (Util.alphaList.Count() -1 < value)        {            Util.IncreaseList();        }        return Util.alphaList.ElementAt(value);    }    private static void IncreaseList()    {        Util.alphaList = Util.alphabetArray.Take(1).Union(            Util.alphaList.SelectMany(currentLetter =>               Util.alphabetArray.Skip(1).Select(innerLetter => currentLetter + innerLetter)            )        );    }}My question is this: Is this approach a better solution (performance wise)? or is a recursive / computed value better (eg. this answer )?
Integer to Alphabet string (A, B, ....Z, AA, AB...)
c#;performance;strings;converting
Calling any function in general will give you a small (miniscule) performance hit.  Recursive functions (AFAIK) cannot be inlined so that can't be optimized away.  LINQ revolves around calling other functions so that's the worst choice to make if you want to write good performing code.  I've said it before, LINQ is not for writing fast code, it's for writing concise code.  This is a simple algorithm that doesn't need to be bogged down by that.* It doesn't help if you don't use LINQ correctly, you have a number of no-no's in your code.If you want the fastest approach (without resorting to mapping out all possible values in memory), you'd stay away from these and do a more direct conversion.  To be the absolutely fastest, you have to get down low-level and use unsafe (unmanaged) code.  I won't go there.  On the other hand, if you want fastest managed code, you'd want to do this iteratively.  In any case, my proposal is not a claim to be the fastest implementation, it could very well not be but I don't know, you would have to profile it to find out.We're doing a base conversion from base-10 numbers to base-26 numbers.  I don't know if there's a faster algorithm to do this but here's a straight conversion using a StringBuilder as a buffer.const int ColumnBase = 26;const int DigitMax = 7; // ceil(log26(Int32.Max))const string Digits = ABCDEFGHIJKLMNOPQRSTUVWXYZ;public static string IndexToColumn(int index){    if (index <= 0)        throw new IndexOutOfRangeException(index must be a positive number);    if (index <= ColumnBase)        return Digits[index - 1].ToString();    var sb = new StringBuilder().Append(' ', DigitMax);    var current = index;    var offset = DigitMax;    while (current > 0)    {        sb[--offset] = Digits[--current % ColumnBase];        current /= ColumnBase;    }    return sb.ToString(offset, DigitMax - offset);}On the other hand, since your inputs are constrained to up to 50'ish, you could just use an array (and not an IEnumerable<>) for the lookups.static readonly string[] Columns = new[]{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ,BA,BB,BC,BD,BE,BF,BG,BH};public static string IndexToColumn(int index){    if (index <= 0)        throw new IndexOutOfRangeException(index must be a positive number);    return Columns[index - 1];}