using System; namespace Method { class Program { // method declaration public string fncGetABC(int iNumber) { if (iNumber < 0) { Console.WriteLine("{0} is less than 0", iNumber); Console.ReadLine(); return " "; } else if (iNumber > 26) { Console.WriteLine("{0} is greater than 26", iNumber); Console.ReadLine(); return " "; } else { string sAlpha = "Z 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"; string[] aAlpha = sAlpha.Split(' '); Console.WriteLine("{0} is greater than 26", iNumber); Console.WriteLine(sAlpha); Console.ReadLine(); return aAlpha[iNumber]; } } public static void Main(string[] args) { // create class object Program p1 = new Program(); //call method Console.WriteLine("14"); Console.WriteLine(p1.GetExcelColumnName(16384)); Console.ReadLine(); } private string GetExcelColumnName(int columnNumber) { string columnName = ""; while (columnNumber > 0) { int modulo = (columnNumber - 1) % 26; columnName = Convert.ToChar('A' + modulo) + columnName; columnNumber = (columnNumber - modulo) / 26; } return columnName; } } } |