Pooja
Pooja

Reputation: 113

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

Lambda expression to convert list int to list string

List<int> lstNum = new List<int>(new int[] { 3, 6, 7, 9 });

Upvotes: 9

Views: 6559

Answers (3)

Slai
Slai

Reputation: 22876

No need for lambda:

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

var lstStr = lstNum.ConvertAll(Convert.ToString);

Upvotes: 3

Willy David Jr
Willy David Jr

Reputation: 9151

This will work as well:

List<string> lstString = lstNum.Select(x => x.ToString()).ToList();

Upvotes: 3

eugenioy
eugenioy

Reputation: 12393

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());

Upvotes: 13

Related Questions