Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get array of string from List<Tuple<int, int, string>>?

I was wondering is there an elegant way of geting string[] from List<Tuple<int, int, string>>?

I'm thinking of .NET way (preferable extension methods and lambda expressions :P)

P.S. Code is from .NET 3.5 project, so Tuple is my own implementation.

like image 240
kyrisu Avatar asked Jun 18 '10 13:06

kyrisu


2 Answers

var strings = list.Select(item => item.Item3).ToArray();
like image 77
Jason Avatar answered Oct 22 '22 21:10

Jason


string[] s = tuples.Select((t) => t.Value3).ToArray();

(assuming "Value3" is the third value of the tuple)

like image 43
Philippe Leybaert Avatar answered Oct 22 '22 20:10

Philippe Leybaert