Writing Alphabets (A to Z) in C# using loop

Niladri.biswas
Posted by Niladri.biswas under C# category on | Points: 40 | Views : 6020
I am basically impressed by the article Writing Alphabets (A to Z) in C# using loop ( http://www.dotnetfunda.com/codes/code1817-writing-alphabets-a-to-z-in-csharp-using-loop.aspx?com=added ) by Sheo Narayan and thought of sharing some more ways of achieving the same. Here are my attempts


Enumerable
.Range('A', 'Z' - 'A' + 1)
.ToList()
.ForEach(i => Console.WriteLine((Char)i));


Another Way

Enumerable
.Range(0, 26)
.ToList()
.ForEach(i => Console.WriteLine(Convert.ToChar(i + 65 + 0)));


For generating Small letters write i + 65 + 32

Another way

"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
.ToCharArray()
.ToList()
.ForEach(i => Console.WriteLine(i));


Hope this helps

Comments or Responses

Posted by: Siyyappan21 on: 2/12/2012 Level:Starter | Status: [Member] | Points: 10
Another Easy way for print A-Z

for(int i=0;i<=26;i++)
{
Console.Write(Convert.ToChar(i+65).ToLower()); // This is for lower
Console.Write(Convert.ToChar(i+65).ToUpper()); // This is for upper
}

Login to post response