Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda expression to convert list int to list string in c#

Tags:

c#

lambda

Lambda expression to convert list int to list string

List<int> lstNum = new List<int>(new int[] { 3, 6, 7, 9 });
like image 527
Pooja Avatar asked May 08 '17 01:05

Pooja


2 Answers

You can use the following to convert a List of int to a List of string:

List<string> lstStr = lstNum.ConvertAll<string>(x => x.ToString());
like image 174
eugenioy Avatar answered Oct 13 '22 02:10

eugenioy


No need for lambda:

var lstNum = new [] { 3, 6, 7, 9 }.ToList();

var lstStr = lstNum.ConvertAll(Convert.ToString);
like image 35
Slai Avatar answered Oct 13 '22 00:10

Slai