Char to String
Can anyone please help me with what should be a simple line of code
I would like to create some columns in a datatable called 'Column A' etc, and I am using this code to try to do create the name.
string ColumnName;
for (int counter = 1; counter <= 26; counter++)
ColumnName = "Column " + Convert.ToString((char) counter + 64);
What happens is the ColumnName holds 'Column 65'. It does not seem to be seeing (char).
If I change the code to the following then it works fine, but thats not how I want to do it. Any ideas on what I am doing wrong please?
string ColumnName;
for (int counter = 65; counter <= 90; counter++)
ColumnName = "Column " + Convert.ToString((char) counter);
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Vimal KandasamyRank #2,151 · 661 reputationPosted Mar 13, 2009, 1:58 AM EDT
what u need exactly?
Column 65,Column 66 etc
[generated by your 1st code]
or
Column A,Column B..
[generated by your 2nd code]
if u need Column A,Column B..it will be generatd your second code... what is the problem in that?
Grant McConville18 reputationPosted Mar 13, 2009, 12:26 PM EDT
Vimal KandasamyRank #2,151 · 661 reputationPosted Mar 13, 2009, 8:12 PM EDT
for (int counter = 1; counter <= 26; counter++)
{
ColumnName = "Column " + Convert.ToString((char)(counter + 64));
}
try this