Chris
Chris

Reputation: 2991

Convert List of longs to string array

What is the best way to convert a List of primitive longs to an array of strings?

I think I'm looking for something fancier than writing my own loop, etc..

Upvotes: 4

Views: 2354

Answers (2)

Sam Harwell
Sam Harwell

Reputation: 99999

This is worth checking against the performance of a select statement.

string[] result = Array.ConvertAll(list.ToArray(), i => i.ToString());

Upvotes: 2

Ahmad Mageed
Ahmad Mageed

Reputation: 96557

This should do the trick:

string[] arr = list.Select(l => l.ToString()).ToArray();

Upvotes: 16

Related Questions