Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Enumerable.Range to a List of Strings

Tags:

c#

linq

In Linq, how do convert Enumerable.Range(1, 31) to a List of strings?

like image 251
LB. Avatar asked Oct 08 '11 00:10

LB.


2 Answers

var list = Enumerable.Range(1, 31).Select(n => n.ToString()).ToList();
like image 139
ChaosPandion Avatar answered Oct 13 '22 16:10

ChaosPandion


    static void Main(string[] args)
    {
        List<string> test;
        test = Enumerable.Range(1, 31).Select(n => n.ToString()).ToList();
        foreach (var item in test)
        {
            Console.WriteLine(item);
        }
        Console.ReadLine();
    }

This one print 31 lines for me :).

enter image description here

like image 27
Allan Chua Avatar answered Oct 13 '22 17:10

Allan Chua